ruk·si

Git
Revert a Bad Rebase

Updated at 2017-04-14 13:30

Did you complete a local rebase or did some other destructive action and want to revert back to state before it all?

# list local changes and find the commit before you broke everything
git reflog
# 1c2ef68 HEAD@{0}: checkout: ...
# cd3980d HEAD@{1}: rebase finished: ...
# cd3980d HEAD@{2}: rebase: ...
# 1c2ef68 HEAD@{3}: rebase: ...
# 5723d8b HEAD@{4}: checkout: ...

# Take the commit identifier for the previous commit of the last rebase chain
git reset --hard 5723d8b