| name | git-rescue |
| description | Sort out git messes and perform history surgery — undo/rewrite commits, resolve conflicted merges and rebases, recover lost code via reflog, find regressions with git bisect. |
Git rescue and history surgery
Git history is not a court record — it's a deliberately authored story of the
project. Everything in git can be undone, so work boldly but carefully.
The argument to this skill describes the mess or the desired history change.
Recipes
- Undo last commit (keep the changes):
git reset --soft HEAD~1.
- Remove one file from the last commit: reset it out,
git rm --cached if
needed, re-commit with --amend.
- Combine the last N commits with a better message: soft-reset past them and
re-commit, or interactive-rebase equivalent via
git rebase.
- Conflicted merge / rebase / cherry-pick: read both sides, reason through
the intent of each change, combine them, then run the test suite before
concluding the merge. Never resolve a conflict without running the tests.
- Recover lost code: search
git reflog, stashes, and other branches for
the missing work; cherry-pick or check out what you find.
- "When did this break?": use
git bisect — write the test condition as a
script (exit 0 = good, non-zero = bad), give bisect the known-good and
known-bad commits, and let the binary search find the culprit.
- Extract a library with history: build a new repo from files of this one,
replaying a commit history that preserves the original authors and dates.
Safety
- Before anything destructive, check
git status and stash or commit
uncommitted work (git stash -u).
- Only rewrite history that hasn't been shared, or that you've confirmed is
safe to force-push (
--force-with-lease, never bare --force).