본문으로 건너뛰기
cccskills
무료GitHub에 공개

ls-git-broken-state-recovery

Diagnose and recover broken Git state and worktree metadata with a staged, low-risk recovery flow. Use when Git reports detached or contradictory HEAD state, phantom worktree locks, orphaned worktree entries, missing refs, 0000000000000000000000000000000000000000 hashes, or branch operations fail with errors like already checked out, unknown revision, not a valid object name, or cannot lock ref.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(8)

  • SKILL.md8.4 KB
  • references/overview.md2.8 KB
  • references/recovery-checklist.md2.2 KB
  • references/symptom-map.md2.5 KB
  • scripts/backup_git_metadata.py6.4 KB
  • scripts/guided_repair_plan.py17.0 KB
  • scripts/regression_harness.py7.2 KB
  • scripts/snapshot_git_state.py8.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Unfuck My Git State

Recover a repository without making the blast radius worse.

Core Rules

  1. Snapshot first. Do not "just try stuff."
  2. Write evidence only beneath the controller-assigned .agents/state/<task-slug>/ directory.
  3. Resolve the per-worktree and common Git directories; never assume .git is a directory.
  4. Prefer non-destructive fixes before force operations.
  5. Inspect reflog and create rescue refs before moving a branch pointer.
  6. Create and verify a metadata backup before any manual metadata edit.
  7. Obtain point-of-risk confirmation for the exact target and values before a force or manual edit.
  8. After each fix, run verification before proceeding.

Rule Ownership

This skill owns Git repair and broken-state recovery behavior. Public maintenance docs can point here, but recovery agents should load this skill before touching Git metadata, index files, worktree metadata, or refs.

  • Use ordinary ls-git-merge-rebase for healthy advanced Git operations.
  • Use this skill when Git commands report contradictory state, missing objects, broken index/cache-tree data, zero hashes, or stale worktree locks.
  • Use the controller-assigned Git-bound task slug. Do not invent a second task-state directory.
  • Do not execute destructive recovery commands while diagnosing or generating a plan.

Fast Workflow

Set the explicit private output boundary once:

TASK_STATE_DIR="$PWD/.agents/state/<controller-task-slug>"
  1. Capture diagnostics beneath that directory:
python scripts/snapshot_git_state.py . --output-dir "$TASK_STATE_DIR"
  1. Route by symptom using references/symptom-map.md.
  2. Generate a plan from a new snapshot. The generator consumes the snapshot path through its JSON manifest rather than guessing the newest directory:
python scripts/guided_repair_plan.py --repo . --output-dir "$TASK_STATE_DIR"
  1. Apply the smallest matching playbook.
  2. Run the references/recovery-checklist.md verification gate.
  3. Escalate only if the gate fails.

For an existing snapshot or explicit routing:

python scripts/guided_repair_plan.py --snapshot "$TASK_STATE_DIR/git-state-snapshots/<stamp>"
python scripts/guided_repair_plan.py --list
python scripts/guided_repair_plan.py --symptom phantom-branch-lock

Snapshot Evidence Contract

snapshot_git_state.py records:

  • porcelain-v2 status and branch headers
  • current branch and symbolic HEAD
  • a resolvable HEAD^{commit} probe
  • per-worktree and common Git directory paths
  • worktree, refs, reflog, remote, and fsck diagnostics
  • snapshot.json, binding the emitted snapshot path to the explicit task output directory

A detached-HEAD diagnosis requires all three signals: # branch.head (detached), an empty git symbolic-ref -q HEAD result, and a resolvable HEAD^{commit}. One signal alone is not enough.

Regression Harness

Use disposable simulations before changing script logic:

python scripts/regression_harness.py
python scripts/regression_harness.py --scenario detached-head

The harness creates temporary repositories and never runs force, reset, prune, metadata-edit, or deletion commands against a user repository.

Playbook A: Orphaned Worktree Metadata

Symptoms:

  • git worktree list shows a path that no longer exists.
  • Worktree entries include invalid or zero hashes.

Start non-destructively:

git worktree list --porcelain
git worktree prune -v
git worktree list --porcelain

If stale entries remain, resolve the shared metadata root:

git rev-parse --path-format=absolute --git-common-dir

Create a verified backup with scripts/backup_git_metadata.py. Then require explicit confirmation naming the exact stale path before removing anything beneath the resolved common Git directory.

Playbook B: Phantom Branch Lock

Symptoms:

  • git branch -d or git branch -D fails with "already used by worktree".
  • git worktree list disagrees with observed branch ownership.
git worktree list --porcelain

Find the worktree using that branch, switch that worktree to another branch or intentionally detach it, then retry the branch operation in the main repository. Treat stale ownership metadata as Playbook A; do not guess a .git/worktrees/... path.

Playbook C: Detached or Contradictory HEAD

For corroborated detached HEAD, preserve the current commit before switching:

git reflog --date=iso -n 20 HEAD
git branch rescue/$(date +%Y%m%d-%H%M%S) HEAD
git switch <known-good-branch>

For contradictory branch and symbolic-ref evidence, run the guided planner with --repo and --output-dir. It automatically creates and verifies a metadata archive before showing manual repair commands.

Playbook D: Missing or Broken Refs

Symptoms: unknown revision, not a valid object name, or cannot lock ref.

Inspect and preserve local history first:

git reflog --date=iso -n 50 HEAD
git show <local-only-tip>
git branch rescue/$(date +%Y%m%d-%H%M%S) <local-only-tip>
git show-ref --verify refs/heads/rescue/<timestamp>

Then fetch and verify the exact remote target:

git fetch --all --prune
git show-ref --verify refs/remotes/origin/<branch>
git rev-parse --verify refs/remotes/origin/<branch>^{commit}

git branch -f moves a branch pointer. Immediately before it, obtain explicit point-of-risk confirmation naming the repository, local branch, verified remote ref, and resolved commit. Only that confirmation authorizes:

git branch -f <branch> refs/remotes/origin/<branch>
git switch <branch>

Last Resort: Manual HEAD Repair

Resolve both metadata roots; linked worktrees have distinct values:

git rev-parse --path-format=absolute --git-dir
git rev-parse --path-format=absolute --git-common-dir

Create and verify the backup automatically:

python scripts/backup_git_metadata.py . --output-dir "$TASK_STATE_DIR"

The command archives the actual metadata directory or directories, verifies the required HEAD members, hashes the archive, and writes a JSON receipt. A failed or missing receipt blocks repair.

After checking the expected branch ref, obtain explicit point-of-risk confirmation naming the repository, expected branch, resolved ref, and backup receipt. Prefer:

git show-ref --verify refs/heads/<branch>
git symbolic-ref HEAD refs/heads/<branch>

If symbolic-ref cannot be used, obtain a second confirmation for the exact resolved per-worktree HEAD path. Use the fallback printed by guided_repair_plan.py; never write to a guessed .git/HEAD path. Immediately run the verification gate.

Verification Gate

Run references/recovery-checklist.md. Minimum bar:

  • git status exits cleanly with no fatal errors.
  • symbolic HEAD matches the intended branch, or detached state is intentional and corroborated.
  • git worktree list --porcelain has no missing paths and no unexplained zero hashes.
  • git fsck --no-reflogs --full has no new critical errors.
  • every rescue ref and changed branch pointer resolves to the expected commit.

Escalation Path

  1. Create a verified metadata archive with scripts/backup_git_metadata.py.
  2. Clone fresh from the verified remote.
  3. Recover unpushed work from rescue refs or reflog and cherry-pick into the fresh clone.
  4. Document the failure mode and add a focused regression scenario.

Automation Hooks

Worktree tooling must enforce:

  • explicit controller task-state output
  • preflight snapshot and state validation
  • per-worktree/common metadata path resolution
  • verified backup before manual metadata repair
  • post-operation verification
  • hard stop on unresolved HEAD/ref inconsistency
  • point-of-risk confirmation before destructive commands

Resources

  • Symptom router: references/symptom-map.md
  • Verification checklist: references/recovery-checklist.md
  • Diagnostic snapshot script: scripts/snapshot_git_state.py
  • Verified metadata backup: scripts/backup_git_metadata.py
  • Guided plan generator: scripts/guided_repair_plan.py
  • Disposable regression harness: scripts/regression_harness.py

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Guide accessibility reviews for UI, documents, and workflows. Use for WCAG-oriented audits, keyboard review, semantics, contrast, and remediation planning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

Use when choosing a LocalSetup Agent-* lane for exploration, research, bounded implementation, or review. Consult the static capability matrix; do not probe account or network availability.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

Guide agent email inbox workflows with prompt-injection defenses. Use for inbound email processing, webhooks, routing, and safety review.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

Navigate and understand codebases using agentlens hierarchical documentation. Use when exploring new projects, finding modules, locating symbols in large files, finding TODOs/warnings, or understanding code structure.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

Use for Agent Q signed encrypted file-drop or mail ship and ingest, private registry v2 setup, queue status, and transport maintenance.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

Inventory wrapper for the alirezarezvani Claude skills bundle. Use when triaging its broad skill catalog and large script surface before any targeted import.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

CruxExperts/LocalSetup62026년 10월 22일 업데이트

CruxExperts의 스킬 모두 보기

이 스킬의 문제 신고