Problem: The latest commit should be adjusted before sharing.
When to use: Before pushing or when rewriting local history is acceptable.
Prerequisites: Local repository
- 1
Keep changes staged
Expected: HEAD moves back one commit
git reset --soft HEAD~1 - 2
Verify state
Expected: Changes shown as staged
git status - 3
Recommit
git commit -m "<new message>"
Common mistakes
- Using --hard when you still need changes.
Related commands: git reset --soft, git status
Related workflows: Undo a pushed commit, Squash commits