Undoing Published Commits with Git

02.24.2015

So let’s say I’ve done some work. I’ve made several commits and I’ve pushed them to GitHub. The next day, I decide that those commits are no good and I want to go back to the way things were at commit “0766c053″. How do I “get rid” of them?

This is something that happens quite often and I have to look up the solution each time. There are many different ways to handle this, but the simplest and safest way that I’ve found is to do this:

git revert --no-commit 0766c053..HEAD
git commit

That will bring the current state of the repository back the commit specified without overwriting history.

Sources

http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit