如何解决GIT:分离头 -> 制作当前头
我错误地提交了一个大的 docker 图像 tar 文件,然后推送了它。 当我注意到推送时间太长时,我中止了它。 然后,我删除了 tar 并进行了新的提交(而不是修改之前的)。
我决定返回,执行 git reset -soft
,删除添加的提交中的文件,并修改该提交。
(我想我在这个时间线的某个时候检查了一个提交)
然后我用 ---force-with-lease
但现在我用 git status 得到了这个:
HEAD detached from adc7f05
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
(未分阶段的变化只是一个小的新的后验变化 - 不适用于问题)
我应该怎么做才能使当前的情况成为头?
git reflog:
dc82def (HEAD) HEAD@{0}: commit (amend): Fix conversion on all converters
adc7f05 HEAD@{1}: checkout: moving from master to HEAD@{3}
ffe3448 (remote-github/main,origin/master,master) HEAD@{2}: reset: moving to HEAD~2
adc7f05 HEAD@{3}: reset: moving to HEAD~1
7b5dbfb HEAD@{4}: commit: Remove tar
adc7f05 HEAD@{5}: commit: Fix conversion on all converters
588e4d5 HEAD@{6}: commit: Add multiline
ffe3448 (remote-github/main,master) HEAD@{7}: commit: Add bulk page
84017af HEAD@{8}: commit: Add export possibility to all models
注意:(我推送到两个存储库,因此出现在 ffe3448 上)
谢谢
解决方法
好吧,你要求去参考日志中的修订版:
checkout: moving from master to HEAD@{3}
这意味着您运行了以下内容:
git checkout HEAD@{3}
这会自动让您进入 detached HEAD
,因为您不再使用分支。现在,你为什么这样做?我不知道..... 但您可以采取以下措施重回正轨:
git checkout 7b5dbfb
git reset --soft adc7f05
git commit --amend --no-edit
# now you have what you would like to have in master,right?
git branch -f master
git checkout master
# now you have to force-push in the other 2 repos (because you rewrote history)
如果你不能强制推送到 repos,你需要在 master 之后通过修订来欺骗他们:
git checkout 7b5dbfb
git reset --soft master
git commit -m "Correcting all the mess I did"
# this is a revision _after_ master that gets the content of the tree to what it was in 7b5dbfb
# if you like it:
git branch -f master
git checkout master
git push remote-github master:main
git push origin master
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。