Undoing Commits: Reset

How `git reset` rewinds history, and the critical differences between `--soft`, `--mixed`, and `--hard`.

Version Control6 min readConcept 20 of 29

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.

  1. 1You made three messy commits while trying to center a div. You want to combine them into one clean commit, but you don't want to lose your code changes. Which command should you use?
  2. 2What is the default behavior of `git reset` if you don't specify a flag like `--soft` or `--hard`?
  3. 3Why is it considered dangerous to use `git reset` on commits that have already been pushed to a remote, shared branch?

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.