How do you undo the last Git commit?
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
| Shortcut | Action | Notes |
|---|---|---|
| git log | Commit history | Show commit history. |
| git log --oneline | One-line log | Show commits in one-line format. |
| git diff | Show diff | Show unstaged changes. |
| git reset HEAD [file] | Unstage | Unstage a staged file. |
| git reset --hard HEAD~1 | Undo last commit | Completely undo the last commit. |
| git stash | Stash changes | Temporarily save current changes. |
| git stash pop | Apply stash | Restore stashed changes. |
| git cherry-pick [hash] | Cherry-pick | Apply a specific commit to current branch. |
From the Git reference (24 entries) · all how-to answers