Skip to content
Latchkey

git fsck --unreachable: Find Dangling Objects

git fsck verifies the integrity of the object database and reports dangling and unreachable objects, which is how you recover commits the reflog has already dropped.

When a clone or fetch in CI leaves a corrupt object, or work was lost beyond the reflog, fsck is the diagnostic. It validates every object and points you at dangling commits you can still rescue.

What it does

git fsck walks the object store, checking connectivity and integrity, and reports objects that are dangling (not referenced) or unreachable (not reachable from any ref). --lost-found writes dangling commits/blobs into .git/lost-found so you can inspect and recover them. It is read-only by default; it does not delete anything.

Common usage

Terminal
git fsck --full
# show unreachable objects (candidates for recovery)
git fsck --unreachable
# dump dangling objects to .git/lost-found
git fsck --lost-found
# recover a dangling commit
git show <dangling-sha>
git branch recovered <dangling-sha>

Options

FlagWhat it does
--fullCheck all object directories, including alternates and packs
--unreachablePrint objects not reachable from any ref
--dangling / --no-danglingShow or hide dangling objects (shown by default)
--lost-foundWrite dangling objects into .git/lost-found
--connectivity-onlySkip per-object checks; only verify reachability (faster)
--strictApply stricter validity checks

In CI

A failed fetch with "early EOF" or "did not receive expected object" often leaves a repo that fsck flags as corrupt; on CI it is usually cheaper to delete the clone and re-fetch than to repair. After git gc --prune=now, fsck shows fewer unreachable objects because they were reclaimed. Use --connectivity-only for a fast sanity check on large repos.

Common errors in CI

"error: object file ... is empty" or "fatal: loose object <sha> is corrupt" means a damaged object, frequently from an interrupted fetch; re-clone. "missing blob/tree <sha>" indicates a broken pack. "dangling commit <sha>" is informational: it is recoverable, not an error.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →