恢复 cherry-pick --abort?

Revert cherry-pick --abort?

在过去的一周里,我从我的 master 分支到另一个分支的 70 多个提交都经过精心挑选,命令如下:

git cherry-pick -x -n <commit-id>
(made some modifications and then)
git commit

状态显示 您的分支领先 'origin/another-branch' 76 次提交。

刚才我以为我可以继续我的任务并选择一些提交。今天的第一个提交是错误的,想撤销这个挑选,并使用命令:

git cherry-pick --abort

砰的一声,所有 70 多个提交似乎都消失了。状态显示 您的分支领先于 'origin/another-branch' 2 次提交。

Reflog 显示最后两行:

c398477f HEAD@{0}: reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd
8369312d HEAD@{1}: checkout: moving from master to another-branch

请说有可能恢复中止? 这些提交 are/was 仅在我的本地分支中。而且,它到底是怎么擦除所有精心挑选的提交的,即使在我明确提交了每一个之后?

这是我一周前开始挑选樱桃时的 reflog:

d8a71aca HEAD@{52}: checkout: moving from another-branch to dev
8369312d HEAD@{53}: commit: xxx
...
3bb1ff07 HEAD@{127}: commit: xxx
2b9b6542 HEAD@{128}: commit: xxx
c398477f HEAD@{129}: reset: moving to HEAD^
b373db60 HEAD@{130}: commit: xxx
c398477f HEAD@{131}: commit: xxx
8fb419aa HEAD@{132}: commit: xxx
844cbe24 HEAD@{133}: reset: moving to 844cbe2499aadcd0d014999ddb6f847c1d940440
844cbe24 HEAD@{134}: reset: moving to 844cbe24
41e7dbed HEAD@{135}: checkout: moving from 844cbe2499aadcd0d014999ddb6f847c1d940440 to aller-dev
844cbe24 HEAD@{136}: checkout: moving from another-branch to 844cbe24
41e7dbed HEAD@{137}: reset: moving to HEAD^
844cbe24 HEAD@{138}: reset: moving to HEAD^
81bf86ac HEAD@{139}: cherry-pick: xxx
844cbe24 HEAD@{140}: checkout: moving from dev to another-branch

reflog --all相同:

c398477f refs/heads/another-branch@{0}: reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd
8369312d refs/heads/another-branch@{1}: commit: xxx
6a4da110 refs/heads/another-branch@{2}: commit: xxx
...
2b9b6542 refs/heads/another-branch@{75}: commit: xxx
c398477f refs/heads/another-branch@{76}: reset: moving to HEAD^
b373db60 refs/heads/another-branch@{77}: commit: xxx
c398477f refs/heads/another-branch@{78}: commit: xxx
8fb419aa refs/heads/another-branch@{79}: commit: xxx

我可以结帐到 8369312d 之前的 reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd吗?

我认为(但无法用上面的文字证明)您一定已经通过多次提交开始了最初的挑选操作,例如,使用类似的东西:

git cherry-pick -x 1234567..fedcba9   # possibly with -n too

这会触发 Git 的 "sequencer"。如果某个单独的拾取操作失败,则剩下的拾取将继续执行,并完全退出命令。这将导致后来的 git cherry-pick --abort 将内容放回已保存的 ORIG_HEAD,使您在其间所做的 70 多个提交似乎消失了。

Can I just checkout to 8369312d which is previous to that reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd?

我相信是的。请注意,这会给你一个 "detached HEAD",这很好。如果 git log 然后显示你想要的,随后的 git checkout -b <newbranch> 将创建一个新的分支名称,你可以使用它来处理提交。