↩️ UndoingCommonly used
How to undo the last commit in Git
Remove or undo the most recent commit, with or without keeping your changes.
Undo commit — keep changes staged
git reset --soft HEAD~1Moves HEAD back one commit. Your changes stay staged and ready to re-commit.
When to use: You committed too early or with the wrong message. Changes are safe.
Undo commit — keep changes unstaged
git reset HEAD~1Moves HEAD back and unstages the changes. Files are modified but not staged.
When to use: You want to review and re-stage changes before committing again.
Undo commit — discard changes completely
git reset --hard HEAD~1Moves HEAD back and permanently deletes all changes from that commit.
Permanently deletes your changes. This cannot be undone unless you have the commit hash.
When to use: You want to completely abandon the last commit and all its changes.