Undo a failed git rebase

2 min read

Ever have a git rebase go wrong? Maybe you had merge conflicts and you missed something, but now that you've completed the rebase, it's hard to tell where things went wrong. Sometimes, in a situation like this, your best bet is to get back to a point before you started the rebase operation. Well, I have to tell you, it's actually pretty easy.

If you find yourself wanting to undo a rebase from the point where you started it, start by running git reflog. The reflog will look something like this (fake commit messages courtesy of Busey Ipsum):

3bf4555 HEAD@{0}: commit: I wrestled a bear once A 750lbs black bear
e4eac1b HEAD@{1}: commit: and were going to Cathedral Rock
77eb998 HEAD@{2}: commit: and thats the vortex of the heart
09a0a10 HEAD@{3}: commit: Its OK to get Rib-grease on your face
7612d5f HEAD@{4}: commit: Its like a symbology of this of your mouth is eating food
ed36f6b HEAD@{5}: commit: These kind of things only happen for the first time once
ef2364b HEAD@{6}: commit: because youre allowing people to see that youre proud of these ribs
00bf2c9 HEAD@{7}: commit: Thats why I enjoy eating in the dark

Once you've selected the action you want to go back to, you just use a hard reset to get back to a good state. So if our target action was the "Its OK to get Rib-grease on your face" commit, we just issue the following command:

git reset --hard HEAD@{3}

Now you can start over from that point. Nice and Simple.