Do you know how to easily undo a git rebase?

Technology CommunityCategory: GitDo you know how to easily undo a git rebase?
VietMX Staff asked 3 years ago

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog

git reflog

and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the --hard option).

Suppose the old commit was HEAD@{5} in the ref log:

git reset --hard HEAD@{5}

Also rebase saves your starting point to ORIG_HEAD so this is usually as simple as:

git reset --hard ORIG_HEAD