Git Rescue¶
Diagnose and recover from git mishaps — lost commits, bad rebases or resets, deleted branches, commits on the wrong branch, or an accidentally committed secret.
Trigger: /git-rescue
How It Works¶
- Diagnose first —
git status,git log,git reflog -20, andgit stash listbefore touching anything. The reflog is the rescue map: it records every place HEAD has been. - Safety net — create a
rescue/<date>branch pointing at the commits to preserve before applying any fix. - One targeted fix — matched to the situation: bad reset (reflog + reset), bad rebase (
ORIG_HEAD), deleted branch (recreate from reflog), wrong branch (branch + reset back), detached HEAD (branch + merge), lost uncommitted work (stash, thengit fsck --lost-found), rewritten pushed branch (--force-with-leasewith confirmation, or revert), committed secret (history cleanup plus credential rotation). - Verify — confirm the recovered work is present in the files, not just that a hash moved.
- Clean up — delete the rescue branch only after the user confirms, and explain what went wrong.
Diagnose, Don't Guess¶
Bad: reacting with more state-changing commands
Each guess overwrites evidence the reflog, stash, or working tree still held.Good: evidence, backup, one deliberate restore
Safety Rules¶
| Rule | Why |
|---|---|
| Backup branch before every fix | A second mistake without one costs the work |
No checkout . / clean / stash drop while diagnosing |
They destroy the uncommitted state that may need recovering |
--force-with-lease, never --force, always confirmed |
Bare force-push silently overwrites collaborators' work |
git revert on shared branches |
History-safe; nobody's clone breaks |
| Pushed secret ⇒ rotate the credential | It's leaked the moment it's pushed, even if force-pushed away |
Notes¶
- The reflog is local-only and expires (default ~90 days) — rescue sooner rather than later.
- Uncommitted changes that were never staged or stashed were never in git; the skill says so honestly instead of pretending.
- For a truly mangled repo, a fresh clone plus cherry-picks from the rescue branch beats surgery in place.
- After a secret cleanup, Secrets Audit confirms nothing else is tracked or still in history.