Progress:
TIER 1 · MODULE 13· Basics

git reset

Three modes. One footgun. Learn it cold.

🎯 What & why

Move the current branch pointer to a different commit, optionally adjusting the index and working tree. Three modes: --soft (just move HEAD), --mixed (default — move HEAD + reset index), --hard (move HEAD + reset index + reset working tree). One footgun, three speeds.

🧠 Mental model

Reset is branch-pointer surgery. --soft moves the pointer; --mixed also resets the index to match the new commit (your working tree changes survive but become unstaged); --hard resets everything, discarding uncommitted work. There is no recovery for --hard outside the reflog.

🛠️ Synopsis

git reset [-q] [<tree-ish>] [--] <pathspec>...
git reset (--patch | -p) [<tree-ish>] [--] [<pathspec>...]
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

🎚️ Switches & options

FlagWhat it does
--soft <commit>Move HEAD to <commit>. Index and working tree untouched. Your changes appear as 'staged for commit'.
--mixed <commit>(default) Move HEAD; reset index to match. Working tree untouched — your changes appear as 'unstaged'.
--hard <commit>⚠️ Move HEAD; reset index and working tree. ⚠️ Destroys uncommitted work.
--keep <commit>Like --hard but refuses if it would discard local changes.
--merge <commit>Reset like --hard but preserves working-tree changes that aren't between the commits.
<commit> -- <path>Restore <path> in the index from <commit>. Doesn't move HEAD.

💡 Use cases

🧪 Examples

Undo the last commit but keep changes staged for a redo.
$ git reset --soft HEAD~1
Undo the last commit and unstage everything (keep edits).
$ git reset HEAD~1   # default: --mixed
Nuke local commits AND working-tree changes back to a known state.
$ git reset --hard origin/main   # ⚠️ destructive
Unstage a single file (legacy form — modern is git restore --staged).
$ git reset HEAD -- src/main.c

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.