SnippetsSnippets

Git undo last commit

Delete the commit and its changes completely:

git reset --hard HEAD~1

To undo the last commit but keep your changes staged:

git reset --soft HEAD~1

Keep the changes but unstage them:

git reset HEAD~1

If commit was pushed to remote and you want to remove it from there as well, then

git push --force

Another option is to add a new commit reverting that commit, useful when you want to keep that commit in your git history

git revert HEAD
git push