Today I Learned

A Hashrocket project

Undo a git mistake

git reflog is a record of your commands in Git. With it, you can undo almost mistake you make with Git.

$ git reflog

4bd0090 HEAD@{0}: <bad change>
46bd839 HEAD@{1}: <bad change>
967e214 HEAD@{2}: <last good change>
46bd839 HEAD@{3}: <good change>
967e214 HEAD@{4}: <good change>

Now:

$ git reset --hard HEAD@{2}

Or:

$ git reset --hard 46bd839