A very quick and easy way to undo git rebase is to return branch labels.
If you are sure you want to discard the current tip of the version2 branch, you can start with git reflog (just like you). I will also include the rebase step rebase , and I will leave some โrealโ shortened links:
$ git checkout branch $ git rebase --onto master start-after branch ... rebase output ... # oops! dag-nab-it! didn't mean to do that! $ git reflog <rev..> HEAD@ {0}: rebase finished: returning to refs/heads/branch <rev..> HEAD@ {1}: rebase: some commit msg... 05f7dc8 HEAD@ {2}: rebase: checkout master aa4e140 HEAD@ {3}: checkout: moving from master to branch
Here aa4e140 is where the HEAD branches are. This is also available in ORIG_HEAD :
$ git log -1 --oneline ORIG_HEAD aa4e140 some commit msg...
(Use more logs if you need to make sure you go to the right place.)
If you have done some other git things since recovery, ORIG_HEAD may have moved, but reflog will have the correct value. If ORIG_HEAD and what you see in the reflog agree, you definitely have the correct value. In any case, make sure that you have the correct value (and that you have no saved changes, that git status clean - you can use git stash , if necessary, here).
Also try git reflog version2 , which will show you the history of the version2 label.
Now just run the current branch - make sure that the one you want to change is still on the target commit:
$ git branch ... see that you're still on "branch" or "version2" or whatever $ git reset --hard aa4e140
Voila, everything went back to how they were before you started git rebase .
If you havenโt done anything to change ORIG_HEAD , this is even easier than all of this:
$ git log ORIG_HEAD
but the reflog method reflog more general (it works about a month 1 after rebase, regardless of what you did between them). A.
( 1 The time period here is configurable, see git reflog . The default is 30 days for reflog entries "not accessible from the current branch tip", which is usually the case for old commits before reinstalling.)
The key to understanding why this works is simple: git rebase stores your old commits. It simply adds new commits to commit-graph, and then moves the label. When the shortcut has moved, it is harder to see your old commits - they are not displayed by default, they are only in the "reflog", but they are still there. Return the label, and the new commits are those that are not displayed, and the old ones are back!