git fsck
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>...]Options
Choosing the Right Option
Finding lost work
First try the reflog
| Command | Finds |
|---|---|
git reflog | Everywhere HEAD has been (easiest) |
git fsck --no-reflogs | Commits no ref reaches |
git fsck --lost-found | Also dangling files (e.g. staged then lost) |
Examples
Check
git fsckSilent when everything is fine.
Find lost commits
git fsck --no-reflogsCommits no branch or tag reaches.
Collect them
git fsck --lost-foundCopies them into .git/lost-found.
Workflow Examples
git fsck --no-reflogsFind dangling commits
git show <hash>Check it
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 commit nothing points to. It is kept until git gc removes it (by default after the reflog entry expires).