git fsck

Administration

Verify the repository and find unreachable objects


The 'git fsck' command (file system check) verifies that every object in the repository is intact and that history is fully connected. It also reports dangling objects — commits and files that nothing points to any more, such as a commit left behind by git reset --hard once the reflog forgets it. Those can still be recovered until git gc deletes them.

Synopsis

git fsck [--unreachable] [--no-reflogs] [--lost-found] [--full] [<object>...]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (2)

Do not count reflog entries as references: report commits only the reflog remembers.

When neededList commits kept alive only by the reflog

Example

git fsck --no-reflogs

Write dangling objects into .git/lost-found (implies --no-reflogs).

When neededCollect lost objects in one place

Example

git fsck --lost-found

Choosing the Right Option

Finding lost work

First try the reflog

CommandFinds
git reflogEverywhere HEAD has been (easiest)
git fsck --no-reflogsCommits no ref reaches
git fsck --lost-foundAlso dangling files (e.g. staged then lost)

Examples

Check

git fsck

Silent when everything is fine.


Find lost commits

git fsck --no-reflogs

Commits no branch or tag reaches.


Collect them

git fsck --lost-found

Copies them into .git/lost-found.

Workflow Examples

1
git fsck --no-reflogs

Find dangling commits

2
git show <hash>

Check it

3
git branch rescue <hash>

Keep it

Troubleshooting

error: object file … is empty / corrupt

Cause: Disk or crash damage

Fetch a fresh copy from the remote; keep a backup of .git first

Tips & Pitfalls

Best Practices

  • ✓Run git fsck when you suspect corruption, before git gc.

Common Mistakes

  • ✗Panicking about "dangling" objects — they are normal leftovers and cleaned by git gc.

FAQ

A:

A commit nothing points to. It is kept until git gc removes it (by default after the reflog entry expires).