Git Reset: Soft, Hard, and Mixed Modes Explained
Understand the difference between git reset --soft, --mixed, and --hard. Learn when to use each mode to undo commits safely in Git.
git reset --soft HEAD~1Detailed Explanation
What Does git reset Do?
git reset moves the current branch pointer to a different commit. The three modes — --soft, --mixed, and --hard — control what happens to the staging area (index) and working directory.
The Three Modes
| Mode | HEAD | Staging Area | Working Directory |
|---|---|---|---|
--soft |
Moves | Unchanged | Unchanged |
--mixed (default) |
Moves | Reset | Unchanged |
--hard |
Moves | Reset | Reset |
--soft: Undo the Commit, Keep Everything Staged
git reset --soft HEAD~1
This is perfect when you want to re-do a commit — the changes remain staged and ready to commit again with a different message or combined with other changes.
--mixed: Undo the Commit, Unstage Changes
git reset HEAD~1
# or explicitly:
git reset --mixed HEAD~1
Changes are preserved in your working directory but are no longer staged. Use this when you want to re-organize which files go into which commit.
--hard: Undo Everything
git reset --hard HEAD~1
This permanently discards changes. The commit, staging area, and working directory are all reverted. Use this only when you are certain you want to throw away work.
Safety Tips
- Always check
git reflogbefore panicking — even--hardresets can be undone if you act before garbage collection. - Prefer
--softor--mixedunless you truly want to destroy uncommitted changes. - Never use
git reseton commits that have been pushed to a shared branch — usegit revertinstead, which creates a new commit that undoes the changes.
Use Case
A developer committed with the wrong message and wants to redo the commit. They use git reset --soft HEAD~1 to undo the commit while keeping all changes staged.