Undoing Commits: Reset
How `git reset` rewinds history, and the critical differences between `--soft`, `--mixed`, and `--hard`.
The git reset command
git reset is a powerful command that rewinds your branch's history to a specific past commit.
Unlike git revert, which adds a new commit to undo changes, reset actively erases recent commits from your local history by pointing HEAD backward.
Why it matters
During development, it's common to make messy, experimental WIP (Work In Progress) commits.
git reset allows you to clean up your local history before pushing, combining messy commits into a single cohesive one (squashing) so your teammates only see clean, logical work.
The Three Modes
git reset operates on the 3 Trees (History, Staging, Working Directory).
--soft: Moves HEAD back, but leaves Staging and Working Directory untouched. Changes are ready to be re-committed.
--mixed (Default): Moves HEAD back and empties the Staging area. Changes exist in your Working Directory, but are unstaged.
--hard: Moves HEAD back, empties Staging, AND overwrites the Working Directory. All uncommitted work is destroyed.
Compare the three reset modes
Inspect how --soft, --mixed and --hard affect HEAD, the index and the working tree.
main -> c3 c3 has parent c2. Index matches c3 (v3). Select a mode to reset to c2.
HEAD / main
c3 / v3
Index snapshot
v3
Tracked working file
v4 (uncommitted edit)
The fixture starts at c3. Each mode is compared from this same starting state.
Soft moves the branch; mixed also resets the index; hard also replaces tracked working content. Hard can lose uncommitted work. Buttons compare the same sample snapshot, not successive reset commands. Local simulation.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
--soft: Uncommits, keeps changes staged.--mixed(default): Uncommits, keeps changes unstaged.--hard: Uncommits, destroys all changes. Use with extreme caution.- Never reset public, pushed commits!
Done with this concept?
Mark it complete to track your progress. No login needed.