NAME

git-fsck - Verifies the connectivity and validity of the objects in the database

SYNOPSIS

  1. git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
  2. [--[no-]full] [--strict] [--verbose] [--lost-found]
  3. [--[no-]dangling] [--[no-]progress] [--connectivity-only]
  4. [--[no-]name-objects] [<object>*]

DESCRIPTION

Verifies the connectivity and validity of the objects in the database.

OPTIONS

  • An object to treat as the head of an unreachability trace.
  • If no objects are given, git fsck defaults to using theindex file, all SHA-1 references in refs namespace, and all reflogs(unless —no-reflogs is given) as heads.

    • —unreachable
    • Print out objects that exist but that aren’t reachable from anyof the reference nodes.

    • —[no-]dangling

    • Print objects that exist but that are never directly used (default).—no-dangling can be used to omit this information from the output.

    • —root

    • Report root nodes.

    • —tags

    • Report tags.

    • —cache

    • Consider any object recorded in the index also as a head node foran unreachability trace.

    • —no-reflogs

    • Do not consider commits that are referenced only by anentry in a reflog to be reachable. This option is meantonly to search for commits that used to be in a ref, butnow aren’t, but are still in that corresponding reflog.

    • —full

    • Check not just objects in GIT_OBJECT_DIRECTORY($GIT_DIR/objects), but also the ones found in alternateobject pools listed in GIT_ALTERNATE_OBJECT_DIRECTORIESor $GIT_DIR/objects/info/alternates,and in packed Git archives found in $GIT_DIR/objects/packand corresponding pack subdirectories in alternateobject pools. This is now default; you can turn it offwith —no-full.

    • —connectivity-only

    • Check only the connectivity of reachable objects, making surethat any objects referenced by a reachable tag, commit, or treeis present. This speeds up the operation by avoiding readingblobs entirely (though it does still check that referenced blobsexist). This will detect corruption in commits and trees, butnot do any semantic checks (e.g., for format errors). Corruptionin blob objects will not be detected at all.

    Unreachable tags, commits, and trees will also be accessed to find thetips of dangling segments of history. Use —no-dangling if you don’tcare about this output and want to speed it up further.

    • —strict
    • Enable more strict checking, namely to catch a file moderecorded with g+w bit set, which was created by olderversions of Git. Existing repositories, including theLinux kernel, Git itself, and sparse repository have oldobjects that triggers this check, but it is recommendedto check new projects with this flag.

    • —verbose

    • Be chatty.

    • —lost-found

    • Write dangling objects into .git/lost-found/commit/ or.git/lost-found/other/, depending on type. If the object isa blob, the contents are written into the file, rather thanits object name.

    • —name-objects

    • When displaying names of reachable objects, in addition to theSHA-1 also display a name that describes how they are reachable,compatible with git-rev-parse[1], e.g.HEAD@{1234567890}~25^2:src/.

    • —[no-]progress

    • Progress status is reported on the standard error stream bydefault when it is attached to a terminal, unless—no-progress or —verbose is specified. —progress forcesprogress status even if the standard error stream is notdirected to a terminal.

CONFIGURATION

  • fsck.
  • During fsck git may find issues with legacy data whichwouldn’t be generated by current versions of git, and whichwouldn’t be sent over the wire if transfer.fsckObjects wasset. This feature is intended to support working with legacyrepositories containing such data.

Setting fsck.<msg-id> will be picked up by git-fsck[1], butto accept pushes of such data set receive.fsck.<msg-id> instead, orto clone or fetch it set fetch.fsck.<msg-id>.

The rest of the documentation discusses fsck. for brevity, but thesame applies for the corresponding receive.fsck. andfetch.<msg-id>.*. variables.

Unlike variables like color.ui and core.editor thereceive.fsck.<msg-id> and fetch.fsck.<msg-id> variables will notfall back on the fsck.<msg-id> configuration if they aren’t set. Touniformly configure the same fsck settings in different circumstancesall three of them they must all set to the same values.

When fsck.<msg-id> is set, errors can be switched to warnings andvice versa by configuring the fsck.<msg-id> setting where the<msg-id> is the fsck message ID and the value is one of error,warn or ignore. For convenience, fsck prefixes the error/warningwith the message ID, e.g. "missingEmail: invalid author/committerline - missing email" means that setting fsck.missingEmail = ignorewill hide that issue.

In general, it is better to enumerate existing objects with problemswith fsck.skipList, instead of listing the kind of breakages theseproblematic objects share to be ignored, as doing the latter willallow new instances of the same breakages go unnoticed.

Setting an unknown fsck.<msg-id> value will cause fsck to die, butdoing the same for receive.fsck.<msg-id> and fetch.fsck.<msg-id>will only cause git to warn.

  • fsck.skipList
  • The path to a list of object names (i.e. one unabbreviated SHA-1 perline) that are known to be broken in a non-fatal way and shouldbe ignored. On versions of Git 2.20 and later comments (#), emptylines, and any leading and trailing whitespace is ignored. Everythingbut a SHA-1 per line will error out on older versions.

This feature is useful when an established project should be accepteddespite early commits containing errors that can be safely ignoredsuch as invalid committer email addresses. Note: corrupt objectscannot be skipped with this setting.

Like fsck.<msg-id> this variable has correspondingreceive.fsck.skipList and fetch.fsck.skipList variants.

Unlike variables like color.ui and core.editor thereceive.fsck.skipList and fetch.fsck.skipList variables will notfall back on the fsck.skipList configuration if they aren’t set. Touniformly configure the same fsck settings in different circumstancesall three of them they must all set to the same values.

Older versions of Git (before 2.20) documented that the object nameslist should be sorted. This was never a requirement, the object namescould appear in any order, but when reading the list we tracked whetherthe list was sorted for the purposes of an internal binary searchimplementation, which could save itself some work with an already sortedlist. Unless you had a humongous list there was no reason to go out ofyour way to pre-sort the list. After Git version 2.20 a hash implementationis used instead, so there’s now no reason to pre-sort the list.

DISCUSSION

git-fsck tests SHA-1 and general object sanity, and it does full trackingof the resulting reachability and everything else. It prints out anycorruption it finds (missing or bad objects), and if you use the—unreachable flag it will also print out objects that exist but thataren’t reachable from any of the specified head nodes (or the defaultset, as mentioned above).

Any corrupt objects you will have to find in backups or other archives(i.e., you can just remove them and do an rsync with some other site inthe hopes that somebody else has the object you have corrupted).

If core.commitGraph is true, the commit-graph file will also be inspectedusing git commit-graph verify. See git-commit-graph[1].

Extracted Diagnostics

  • expect dangling commits - potential heads - due to lack of head information
  • You haven’t specified any nodes as heads so it won’t bepossible to differentiate between un-parented commits androot nodes.

  • missing sha1 directory

  • The directory holding the sha1 objects is missing.

  • unreachable

  • The object , isn’t actually referred to directlyor indirectly in any of the trees or commits seen. This canmean that there’s another root node that you’re not specifyingor that the tree is corrupt. If you haven’t missed a root nodethen you might as well delete unreachable nodes since theycan’t be used.

  • missing

  • The object , is referred to but isn’t present inthe database.

  • dangling

  • The object , is present in the database but neverdirectly used. A dangling commit could be a root node.

  • hash mismatch

  • The database has an object whose hash doesn’t match theobject database value.This indicates a serious data integrity problem.

Environment Variables

  • GIT_OBJECT_DIRECTORY
  • used to specify the object database root (usually $GIT_DIR/objects)

  • GIT_INDEX_FILE

  • used to specify the index file of the index

  • GIT_ALTERNATE_OBJECT_DIRECTORIES

  • used to specify additional object database roots (usually unset)

GIT

Part of the git[1] suite