Skip to content

Undo last commit

Removes the commit but leaves the changes staged in your working tree:

Terminal window
git reset --soft HEAD~1

Destructive — the changes are gone from the working tree:

Terminal window
git reset --hard HEAD~1

Change the message, or stage more files and fold them in:

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

Reset and amend rewrite history, so you need to force-push. Always --force-with-lease over --force — it refuses to overwrite work pushed by someone else in the meantime:

Terminal window
git push --force-with-lease

git reflog keeps every commit HEAD has touched for ~90 days — see Recover from a bad reset.