Files
skills/skills/git-manager/references/recovery.md
T
kiskaadee 383fcf3db6 feat(git-manager): unify git-commit and git-workspace into git-manager
- Archive skills/git-commit to archive/skills/git-commit and document in archive/README.md
- Evolve skills/git-workspace into skills/git-manager (66 lines <= 80)
- Add references/commits.md covering slice boundaries, staging discipline, Conventional Commit depth matching, pre-commit gate, and session-mode execution
2026-10-31 20:51:52 -05:00

2.2 KiB

Evidence-First Git Recovery

Reference for git-manager. Procedures for diagnosing and recovering lost commits, detached heads, botched rebases, or corrupted refs using observable evidence.

Core Invariant

Never propose a destructive command (git reset --hard, git checkout -f, git clean -fd) as a speculative remedy. Destructive commands discard uncommitted files permanently. Always inspect evidence first, locate candidate commit SHAs, and restore state into a new named branch.

1. Inspect Current State Before Acting

Check working-tree and ref state:

git status --short
git branch -v
git log -n 5 --oneline

If working-tree changes exist, stash or commit them before attempting ref recovery:

git stash push -m "WIP before reflog recovery"

2. Reflog Inspection

The reflog records every update to local branch tips and HEAD.

  • Inspect recent HEAD movements:

    git reflog -n 20 --date=iso
    
  • Look for state transitions:

    • rebase (finish) / rebase (start): find the commit immediately preceding rebase (start).
    • reset: moving to ...: find the SHA prior to the reset.
    • commit: ...: locate orphaned commits from deleted or moved branches.
  • Inspect branch-specific reflog:

    git reflog show <branch-name>
    

3. Verify Candidate Commit

Inspect the candidate SHA before restoring:

git show <candidate-sha> --stat
git log -1 -p <candidate-sha>

Confirm that the commit contains the expected changes and history.

4. Non-Destructive Restoration

Never mutate current branch in place with --hard reset. Instead, point a dedicated recovery branch at the discovered SHA:

git branch recovery/<topic> <candidate-sha>

Verify the recovered branch:

git log -n 3 --oneline recovery/<topic>

Then switch to the recovery branch cleanly:

git switch recovery/<topic>

5. Dangling and Unreachable Objects (Last Resort)

If a commit was not captured in the reflog (e.g. reflog expired or repository corruption):

git fsck --lost-found

Dangling commits appear in .git/lost-found/commit/. Inspect each candidate:

git log -1 -p <dangling-sha>

Once found, create a branch off it:

git branch recovery/<topic> <dangling-sha>