Skip to content

Undo last commit

Keep changes in working tree, only remove the last commit:

Terminal window
git reset --soft HEAD~1

Discard the last commit and its changes (destructive):

Terminal window
git reset --hard HEAD~1

Amend the last commit (change message or add more changes):

Terminal window
git commit --amend -m "New message"
# or stage more files, then:
git commit --amend --no-edit

If already pushed, you need to force-push after reset/amend: git push --force-with-lease (prefer over --force to avoid overwriting others’ work).