GIT: 分离头 -> 建立当前头

GIT: Detached Head -> make current head

我误提交了一个很大的docker图像tar文件,然后推送了它。 当我注意到推送花费的时间太长时,我中止了它。 然后,我删除了 tar 并做了一个新的提交(而不是修改之前的)。

我决定返回,执行 git reset -soft,删除提交时添加的文件,然后修改该提交。 (我想我在这个时间线的某个时候检查了一个提交) 然后我用 ---force-with-lease

但现在我得到了 git 状态:

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 重新登录:

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, origin/master, master) HEAD@{7}: commit: Add bulk page
84017af HEAD@{8}: commit: Add export possibility to all models

注意:(我推送到两个存储库,因此出现在 ffe3448 上)

谢谢

好吧,您要求在 reflog 中进行修订:

checkout: moving from master to HEAD@{3}

这意味着您 运行 类似于:

git checkout HEAD@{3}

这将自动让您进入 detached HEAD,因为您不再使用 b运行ch。现在,你为什么要那样做?我不知道......但是你可以做些什么来回到正轨:

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)

如果你不能强行推送到回购协议中,你需要用一个修订来欺骗他们跟随主人:

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