In Git, how do you rollback a rebase if you're not happy with it?
Git doesn't have dry-run for rebase. If I did a rebase and have not pushed it yet, how do I rollback to before, as if it never happened?
git
In Git, how do you rollback a rebase if you're not happy with it?
Git doesn't have dry-run for rebase. If I did a rebase and have not pushed it yet, how do I rollback to before, as if it never happened?
Best Answer
You can use the reflog to find the first action before the rebase started and then reset --hard back to it. e.g.
Now you should be back to before the rebase started.
To find the right place to reset to, you just pick the entry closest to the top that doesn't start with "rebase".
Update: As mentioned in comments and other answers, you can also use
ORIG_HEAD
as an easier way to find where to reset to:git reset ORIG_HEAD --hard
Alternative approach
If the rebase is the only thing you have done on the branch, i.e. you have no unpushed commits/changes - then you could just delete the local branch with
git branch -D
and then check it out again:Or for the same effect, you could reset --hard to the origin branch:
If you did do this while you had other unpushed commits, then you will have lost them. In that case, just use the reflog approach above to jump back to the reflog entry where you made the commit(s).