Summary: Undoing things
The recovery map
Section titled “The recovery map”Six commands. Each maps to a different scenario:
| Scenario | Command |
|---|---|
| Discard working-directory changes | git restore <file> |
| Unstage a staged file | git restore --staged <file> |
| Fix the last commit (local only) | git commit --amend |
| Undo a local-only commit | git reset (with —soft / —mixed / —hard) |
| Undo a pushed commit | git revert <commit> |
| Recover from destructive operations | git reflog + git reset --hard <hash> |
The four reset modes (memorize)
Section titled “The four reset modes (memorize)”| Mode | Commit pointer | Staging area | Working directory |
|---|---|---|---|
--soft | Moves back | KEPT | KEPT |
--mixed (default) | Moves back | CLEARED | KEPT |
--hard | Moves back | CLEARED | CLEARED (destructive) |
The reset vs revert distinction
Section titled “The reset vs revert distinction”- Reset rewrites history. Use only for local-only commits.
- Revert adds new history (an inverse commit). Use for anything pushed.
- Wrong choice: running
git reseton pushed history. Wrong because it forces other team members into ugly merge resolution.
The reflog is your safety net
Section titled “The reflog is your safety net”- Records every HEAD movement for ~90 days.
- Lets you recover from
git reset --hard, lost branches, bad force-pushes, etc. - Only exists on your machine. Cannot recover what was never on your machine.
- The discipline: before you panic, run
git reflog.
Phase 1 is closed
Section titled “Phase 1 is closed”You have:
- Mental model (L1)
- Commands and discipline (L2 + L3)
- Recovery (L4)
That is confident solo git workflow. Phase 2 adds collaboration.
What you carry into Phase 2
Section titled “What you carry into Phase 2”The recovery toolkit. Every time you experiment in Phase 2 (branches, merges, conflicts), the safety net from L4 is what lets you experiment without fear.
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
Undoing is just navigating to a different snapshot. Recovery is just remembering which snapshot you wanted. Almost nothing is truly lost.