How can I undo a `git commit` locally and on a remote after `git push`

michael picture michael · Jun 23, 2011 · Viewed 135.6k times · Source

I have performed git commit followed by a git push. How can I revert that change on both local and remote repositories?

$ git log
commit 364705c23011b0fc6a7ca2d80c86cef4a7c4db7ac8
Author: Michael Silver <Michael [email protected]>
Date:   Tue Jun 11 12:24:23 2011 -0700

Answer

Alexander Gro&#223; picture Alexander Groß · Jun 23, 2011
git reset --hard HEAD~1
git push -f <remote> <branch>

(Example push: git push -f origin bugfix/bug123)

This will undo the last commit and push the updated history to the remote. You need to pass the -f because you're replacing upstream history in the remote.