agentsclimarketplace

Git data recovery

Skill narenaryan/agent-skills/skills/git/git-data-recovery

Byte-sized agent skills for giving advanced knowledge to AI agents

Install
npx -y skills add narenaryan/agent-skills --skill git-data-recovery

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when commits or branches seem lost — after hard reset, force-push, branch delete, or botched rebase — to locate dangling objects via reflog and fsck before gc prunes them

SKILL.md

2.0 KB, as published. Nobody here has run it

Git Data Recovery

Lost commits survive until gc prunes (default: 14 days dangling, 90 days reflog-reachable). Recovery is a race against gc.

Path 1: Reflog (for commits you were on)

git reflog                     # HEAD history
git reflog show <branch>       # per-branch
git log -g --oneline           # same as log

git branch rescue <sha>
git reset --hard HEAD@{5}
git cherry-pick HEAD@{1}

Reflog is local, per-ref. A fresh clone has none.

Path 2: fsck (when reflog is gone)

git fsck --full --no-reflogs --unreachable --lost-found
# dangling commit abc...

--lost-found writes objects to .git/lost-found/{commit,other}/.

Inspect candidates:

for sha in $(git fsck --no-reflog --unreachable | awk '/commit/ {print $3}'); do
  git log -1 --format='%h %ci %s' "$sha"
done
git branch rescue <sha>

Path 3: One File from a Commit

git show <sha>:path > recovered
git checkout <sha> -- path

Protect Before Risky Ops

git tag rescue/$(date +%s) HEAD
git update-ref refs/rescue/before-rebase HEAD

Any ref under refs/ keeps objects reachable indefinitely.

gc / Prune

  • Auto-triggers at ~7,000 loose objects or 50+ packfiles.
  • git gc --prune=now immediately deletes unreachable objects — do not run during recovery.
  • git reflog expire --expire-unreachable=now --all && git gc --prune=now destroys recovery paths.

Find Large Objects

git rev-list --objects --all \
  | git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' \
  | awk '$2=="blob"{print $3,$4}' | sort -n | tail -20

Purge: git filter-repo --path <file> --invert-paths.

Pitfalls

  • Debug on the original working copy; a fresh clone has no reflog.
  • Don't "clean up" before verifying recovery — many one-liners silently destroy it.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.