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.
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.