git fsck
git
Usage
git fsck [--lost-found] [--unreachable]Checks the object database and lists commits nothing points at, the second way to find work lost after a reset once the reflog entry is gone; it reports, it does not repair.
Common flags
| Flag | Meaning |
|---|---|
| --lost-found | write dangling objects into .git/lost-found |
| --unreachable | list objects no ref points at |
| --dangling | list objects nothing at all refers to |
| --full | check packs and alternates too |
| --connectivity-only | skip the expensive object checks |
| --no-reflogs | do not treat reflog entries as roots |
Examples
git fsck --lost-foundrecovers commits after a reset when the reflog is gone
git fsck --unreachablelists commits nothing points at any more
git fsck --connectivity-onlya quick structural check on a huge repository
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git fsck do?
Checks the object database and lists commits nothing points at, the second way to find work lost after a reset once the reflog entry is gone; it reports, it does not repair.
Q. How do I type it?
git fsck [--lost-found] [--unreachable] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-fsck