How do you undo the last Git commit?

Git · History & Undo · updated 2026-08-23

git reset --hard HEAD~1 — Undo last commit

git reset --hard HEAD~1 removes the last commit and discards its changes from the working tree. If you want to keep the changes as uncommitted edits, use the same command without --hard.

Related Git shortcuts: History & Undo

ShortcutActionNotes
git logCommit historyShow commit history.
git log --onelineOne-line logShow commits in one-line format.
git diffShow diffShow unstaged changes.
git reset HEAD [file]UnstageUnstage a staged file.
git reset --hard HEAD~1Undo last commitCompletely undo the last commit.
git stashStash changesTemporarily save current changes.
git stash popApply stashRestore stashed changes.
git cherry-pick [hash]Cherry-pickApply a specific commit to current branch.

From the Git reference (24 entries) · all how-to answers