Home·Terminal commands

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

FlagMeaning
--lost-foundwrite dangling objects into .git/lost-found
--unreachablelist objects no ref points at
--danglinglist objects nothing at all refers to
--fullcheck packs and alternates too
--connectivity-onlyskip the expensive object checks
--no-reflogsdo not treat reflog entries as roots

Examples

git fsck --lost-found

recovers commits after a reset when the reflog is gone

git fsck --unreachable

lists commits nothing points at any more

git fsck --connectivity-only

a 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