Thursday, August 14, 2014

Undo and Recover from a Rebase Mistake

I had 3 local commits and I wanted to squash them.  So naturally I did:

git rebase -i

However, it was 6pm and I was tired so instead of putting little s in front of each commit I wanted to squash, I pressed dd twice in vim, which deleted both of those lines.  What happened next is that I lost those two commits in the local branch.

Luckily underneath, git still has those two commits:

git reflog

But the dag does not show them as expected:

git dag --all

To fix it, I took the commit that I wanted in git reflog and merged it with my current branch:

git merge 1482cc4

And then did a rebase correctly.