还原樱桃挑选 - 是什么?

时间:2017-11-10 00:13:50

标签: git git-cherry-pick

在过去的一周里,我从主分支机构挑选了超过70个提交到命令的另一个分支:

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

状态显示您的分支在76次提交之前超过“origin / another-branch”。

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

git cherry-pick --abort

繁荣,所有70多个提交似乎都消失了。状态显示您的分支在2次提交之前超过“origin / another-branch”。

Reflog显示最后两行:

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

请说以某种方式可以恢复中止?这些提交只在我的本地分支中进行。并且,即使在我明确地提交了每一个提交之后,它到底如何擦除所有樱桃选择的提交?

这是我一周前开始采摘樱桃时的点击日志:

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吗?

1 个答案:

答案 0 :(得分:0)

我认为(但不能用上面的文字证明)你必须通过多次提交启动最初的挑选操作,例如使用类似的东西:

classpath 'com.android.tools.build:gradle:2.3.3'

这会触发Git的“音序器”。如果某些单独的选择操作失败,那么剩下的选择将完成,并完全退出命令。然后,这会导致后来的git cherry-pick -x 1234567..fedcba9 # possibly with -n too 将事物放回到已保存的git cherry-pick --abort中,使得你之间做出的70多个提交似乎消失了。

  

我可以结帐到ORIG_HEAD之前的8369312d吗?

我相信。请注意,这将为您提供“分离的HEAD”,这很好。如果reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd然后显示您想要的内容,则后续的git log将创建一个新的分支名称,您可以使用该名称来处理提交。