How to undo the last commit in Git
If you haven't pushed yet, run git reset --soft HEAD~1: the commit disappears and its changes stay staged. If you already pushed it, use git revert <commit> instead, which adds a new commit that undoes it without rewriting shared history.
Step by step
Undo the commit but keep the changes staged:
$ git reset --soft HEAD~1Or keep the changes but unstaged:
$ git reset HEAD~1Or throw the changes away completely (careful):
$ git reset --hard HEAD~1Already pushed? Undo it with a new commit instead:
$ git revert <commit-id>
HEAD~1 means "one commit before the current one". The undone commit isn't deleted right away: git reflog can still find it.