What's the difference between git reset --mixed, --soft, and --hard?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
git reset --soft, --mixed, and --hard all move HEAD, but they differ in what happens to the index and working tree. The easiest way to choose correctly is to think in three layers: commit history, staging area, and files on disk. Once that model is clear, reset behavior becomes predictable.
Three-Layer Model
Git state can be viewed as:
- '
HEADpointer to current commit' - index or staging area
- working tree files
Every reset mode moves HEAD. The chosen flag controls whether the index and working tree are also changed.
--soft: Keep Staging and Files
git reset --soft <target> moves HEAD only. Staged and unstaged changes remain as they were.
Typical use cases:
- rewrite commit message
- squash local commits
- split history later while preserving staging context
Because staging is preserved, you can recommit immediately with updated metadata.
--mixed: Unstage But Keep Files
git reset --mixed <target> moves HEAD and resets the index to target commit. Working tree files remain changed.
Typical use cases:
- unstage everything for selective restaging
- split one commit into multiple focused commits
This is usually the safest cleanup mode for local history editing.
--hard: Reset Everything to Target
git reset --hard <target> moves HEAD, resets index, and rewrites working tree files to match target commit.
Typical use cases:
- intentionally discard local work
- force local branch to exactly match another ref
This is destructive for uncommitted changes.
Safety Practices Before Reset
Before any reset, check current state and recent history.
If uncertain, create a recovery point:
Or stash first:
These safeguards avoid avoidable data loss during history edits.
Local Versus Shared Branches
git reset rewrites local branch history. If commits were already pushed, reset plus force push can disrupt collaborators.
On shared branches, prefer git revert for safe undo semantics. If history rewrite is necessary, coordinate and use:
This reduces accidental overwrite risk compared with plain force push.
Practical Decision Guide
Use this quick rule:
- choose
--softwhen you want to keep staging unchanged - choose
--mixedwhen you want file edits but cleared staging - choose
--hardonly when discarding local edits is intentional
Documenting this in team onboarding material prevents many accidental destructive resets.
If you are teaching new contributors, run all three modes on a disposable practice repository first. Seeing index and working-tree differences in git status after each reset builds intuition faster than memorizing definitions.
Common Pitfalls
- Using
--hardwhen only unstaging was intended. - Forgetting that
git resetdefaults to--mixed. - Rewriting already-pushed history without team coordination.
- Skipping
git statusbefore destructive commands. - Assuming discarded local edits are always recoverable.
Summary
- All reset modes move
HEAD. - '
--softkeeps index and working tree untouched.' - '
--mixedresets index while preserving file changes.' - '
--hardresets index and files to target commit.' - Choose mode based on exactly what local state you want to preserve.
Related reading
- What's the difference between git reset and git checkout?
- What''s the difference between Git Revert, Checkout and Reset?
- What's the difference between 'git switch' and 'git checkout' <branch>?
- What's the difference between 'git switch' and 'git checkout' branch?
- What's the difference between HEAD^ and HEAD~ in Git?
- What's the difference origin master vs origin/master
- What's the fastest algorithm for sorting a linked list?
- What's the proper way to go get a private repository?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.