Reputation: 2482
I had cherry-picked over 70 commits over the past week from my master branch to another branch with commands:
git cherry-pick -x -n <commit-id>
(made some modifications and then)
git commit
Status says Your branch is ahead of 'origin/another-branch' by 76 commits.
Just a moment ago I thought I could continue my task and pick some commits. The very first commit for today was a wrong one and wanted to undo this cherry-picking, and used the command:
git cherry-pick --abort
And boom, all the 70+ commits seem to be gone. Status says Your branch is ahead of 'origin/another-branch' by 2 commits.
Reflog show these last 2 lines:
c398477f HEAD@{0}: reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd
8369312d HEAD@{1}: checkout: moving from master to another-branch
Please say there's somehow possible to revert the abort? These commits are/was only in my local branch. And, how the hell did it wipe all the cherry-picked commits, even after I explicityly commited each one of them?
This is the reflog just when I started my cherry-picking a week ago:
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
And same with 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
Can I just checkout to 8369312d
which is previous to that reset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd
?
Upvotes: 3
Views: 17149
Reputation: 487993
I think (but can't prove with the above text) that you must have kicked off the initial cherry-picking operation with more than one commit, e.g., using something like:
git cherry-pick -x 1234567..fedcba9 # possibly with -n too
This would have triggered Git's "sequencer". If some individual pick operation failed, that would leave the remaining picks to do, and exit out of the command entirely. This would then cause the later git cherry-pick --abort
to put things back to the saved ORIG_HEAD
, making the 70-some-odd commits you made in between seem to vanish.
Can I just checkout to
8369312d
which is previous to thatreset: moving to c398477fa2b2e0e78cb628c75df81b2c1ec411cd
?
I believe so. Note that this will give you a "detached HEAD", which is fine. If git log
then shows what you want, a subsequent git checkout -b <newbranch>
will create a new branch name you can use to work with the commits.
Upvotes: 2