Git Delete Commit

To keep myself from looking when it happens again, here’s a personal reference of how to delete a commit:

If you made a commit, but have not pushed it to others:

git reset HEAD^

OR

git reset HEAD~1

both HEAD^ and HEAD~1 are shortcuts for the commit before head.

The above command will make sure you don’t lose your changes – instead, the commit will be deleted and your files will state they are locally modified. It’s the same thing as doing git reset –soft HEAD^

To delete your commit as well as ALL local changes including any staged, uncommitted, changes (remember, only if you haven’t pushed it to others):


git reset --hard HEAD^

If you already pushed your commit, you need to create a new commit that reverses your mistake.


git revert HEAD