Git recovery
Git almost never loses data — it just hides the undo buttons. Three layers of “wait, go back”:
rerere — reuse recorded resolution
git config --global rerere.enabled true and git remembers how you resolved each conflict hunk, replaying the same resolution automatically next time the identical conflict appears (merges and rebases). Escape hatch from recurring-conflict hell: long-lived branches that keep colliding on the same hunks resolve themselves after the first manual pass. skipcloud’s walkthrough (capture: clippings/gist-github-com-skipcloud-f1033afb4fa5681d69fa63458cc95928.md).
ORIG_HEAD — the hidden undo button
Before destructive moves (reset --hard, rebase, merge) git saves the previous HEAD into ORIG_HEAD. Messed up a rebase, reset over your work, merged the wrong branch? git reset --hard ORIG_HEAD — no reflog digging. It only holds one step back, so it’s the first thing to try, with git reflog as the deeper archive. Icinga’s writeup (capture: clippings/icinga-com-blog-undo-git-reset-hard.md).
rebase -i is not that scary
The fear is vocabulary, not mechanics: git rebase -i HEAD~4 opens a todo list where each commit is a line you can reorder, squash, edit, or drop. akrm al-hakimi’s walkthrough (capture: clippings/cachebag-sh-journal-interactive-rebasing.md) — pairs with Jessica Kerr’s diagnosis that git docs are “unintelligible until after you know everything” (Jessica Kerr Git Happens). Pairs with atomic commits: small commits make every todo-list operation low-stakes (Git commit messages).
Structural prevention
The best recovery is the one you don’t need: mergiraf (OSS) resolves conflicts syntax-aware before they reach you, rerere replays your past resolutions, and the DAG model knowledge (commits are snapshots, refs are pointers — Git Will Finally Make Sense After This) is what makes reflog/ORIG_HEAD legible instead of scary.
Related: Git commit messages · Git hooks (pre-commit prevents the mess) · Git worktrees · CIA git tips
The comprehensive source: git-flight-rules
git-flight-rules (OSS) (42.6k★, CC-BY-SA) — the scenario-indexed git recovery manual: “I want to…” / “I did X, how do I undo it” recipes for every disaster class — commits (amend, wrong-message, wrong-author, undo-after-push), branches (deleted/restored, misnamed), merge/rebase (conflicts, aborted, wrong-branch merges, refs/stage), stash, tags, submodules, and the miscellany (deleted file from any commit, accidentally committed sensitive data -> history rewrite). The NASA framing is the keeper (Chris Hadfield, An Astronaut’s Guide): flight rules are “the hard-earned body of knowledge… step-by-step, what to do if X occurs, and why” — Mercury-era lessons-learned compendium as the model for incident documentation.
This note’s rerere/ORIG_HEAD entries are single instruments from that manual’s orchestra; git-flight-rules is the whole book. Ops kin: it’s the git instance of the runbook genre — same shape as Ops toolbelt’s OWASP recipes and Senior mindset’s scar-tissue checklist: failure-shaped situations, indexed by symptom, each with the tested fix.