Undo a git commit

Undo a git commit

Posted on 2013-01-31 by Ed Braaten

I did a local ‘git commit’ from the wrong terminal window this morning – and then pushed it to the server repo. It’s a case of being logged into too many systems at the same time… The changes I wanted to commit were actually on a different system. Fortunately, the fix for my scenario was easy:

git reset –hard HEAD~1
git push -f

This is probaby not a nice way to handle this if anyone is using the repo between the errant commit and the undo. A better way would be to do the following:

git revert <SHA of errant commit>
git push

This will put a new commit on the repo that undoes whatever the specified commit did.

Copyright (C) 2013 by Ed Braaten.  All rights reserved.
Other Blog Entries