Theory
Theory: Reset Moves Names; Restore Copies Bytes; Revert Adds a Commit
Three different operations get called “undo.” They act on different trees and different audiences.
Invariants
| Tool | What it moves | History |
|---|---|---|
git restore |
Working tree and/or index, from a source | Names unchanged |
git reset (no path) |
HEAD (and maybe index, working tree) |
Branch name slides; old commit may become unreachable |
git reset (with path) |
Index (mixed) for those paths | HEAD stays |
git revert |
Nothing; writes a new commit | History goes forward |
Soft / mixed / hard is which of the three trees follow HEAD when you reset a commit:
HEAD index worktree
--soft moves stays stays
--mixed moves matches HEAD stays (default)
--hard moves matches HEAD matches HEAD
Why checkout split
Old git checkout meant both “switch branch” and “restore file.” Git 2.23+ splits them: switch for branches, restore for files. This book uses the split so a command’s name is its theory.
What can break
reset --hardon a sharedmain.- Confusing mixed reset (unstage all) with hard (throw away tracked work).
- Expecting
--hardorrestoreto delete untracked files. They stay. Removing them isgit clean.
How to read this chapter
Three modes, the comparison table as practice, path reset, switch/restore/checkout, then a lab that walks one commit through soft, mixed, and hard on Linux.