Diagnosis-First Recovery: Preserve Before Repair
Start with the symptom
A failed command is evidence, not a diagnosis. In the Garden fixture a branch switch is refused because notes.txt has local edits. Record the exact command, exit status, repository path and intended result. Stop repeated writes. Never start with a hard reset, clean, force push or garbage collection.
Collect evidence
In a trusted complete local repository, inspect HEAD, staged and unstaged changes, untracked files and recent history. The commands below are inspection steps, not a repair. A detached HEAD may have no branch name; an unborn branch has no commit. A partial clone may fetch missing objects. Keep sensitive diffs, paths and remote URLs private; redact before sharing.
git status --short --branchgit diff --statgit diff --cached --statgit log --oneline --graph --all -n 12git reflog -n 5Preserve each kind of work
A rescue branch protects a known existing commit, not an unstaged edit or untracked file. Copy valuable working files and, when possible, take a consistent repository snapshot outside the worktree after stopping writers. Include linked worktree metadata and external object storage if relevant. A patch alone omits untracked files and may omit binary data. Verify backup contents before repair; do not expose secrets in incident reports.
Practice and verify
In chapter35.py inspect the recorded refusal, verify the saved working bytes and index, and compare the pre/post HEAD. A correct diagnosis explains why no branch movement occurred. Choose the smallest repair that preserves needed work, then inspect status again and record remaining uncertainty.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Diagnosis-First Recovery: Preserve Before Repair — knowledge check
Choose evidence-based troubleshooting and data-preserving recovery.
What is the first response to an unexplained failed command?
What does a rescue branch preserve?
Which is absent from ordinary diff output?
What should you share with support?
When is repair complete?