Reset the last commit while keeping all changes staged and ready to re-commit.
git reset --soft HEAD~1
Your files stay exactly as they were. The commit is gone, but the changes are staged (in the index), ready for a new commit.
When to use this
- You committed with the wrong message
- You want to add more changes to the commit
- You committed to the wrong branch and need to move changes
The three reset modes
| Mode | Commit | Staging area | Working directory |
|---|---|---|---|
--soft |
Undone | Kept | Kept |
--mixed (default) |
Undone | Cleared | Kept |
--hard |
Undone | Cleared | Cleared |
Use --soft when you want to redo the commit. Use --mixed when you want to restage selectively. Never use --hard unless you want to discard changes entirely.
Gotchas
- Only works for unpushed commits. If you already pushed, use
git revertinstead: it creates a new commit that undoes the previous one without rewriting history. HEAD~1means “one commit back.” UseHEAD~3to undo the last 3 commits (changes from all 3 are kept staged).- If you need to undo a merge commit, add
-m 1to specify the parent:git reset --soft HEAD~1still works, but check which parent you want.