LinuxCommandLibrary

git-fsck

Check Git repository integrity

TLDR

Check the current repository

$ git fsck
copy

List all tags found
$ git fsck --tags
copy

List all root nodes found
$ git fsck --root
copy

SYNOPSIS

git fsck [--strict] [--no-full] [--lost-found] [--connectivity-only] [--unreachable] [--cache] [--no-cache] [--progress] [--no-progress] [--verbose] [--disk-usage] [--name-objects] [--root <object>] [--ignore-reflog] [--stdin] [<object>…​]

PARAMETERS

--strict
    Check more strictly, enabling more error reports.

--no-full
    Do not load the index nor any commit-graphs.

--lost-found
    Write dangling objects into .git/lost-found.

--connectivity-only
    Check only the connectivity of the objects.

--unreachable
    Show unreachable objects.

--cache
    Use the index cache.

--no-cache
    Do not use the index cache.

--progress
    Show progress bar.

--no-progress
    Do not show progress bar.

--verbose
    Be verbose.

--disk-usage
    Compute disk usage.

--name-objects
    Name dangling objects using git name-rev.

--root <object>
    Consider <object> as a root.

--ignore-reflog
    Ignore reflogs.

--stdin
    Read objects to fsck from stdin.

[<object>…​]
    Objects to fsck.

DESCRIPTION

git-fsck verifies the connectivity and validity of objects in the Git database. It checks for corrupted objects, dangling commits, and other inconsistencies that might indicate data loss or repository corruption. It's a crucial command for maintaining the integrity of your Git repository, especially after operations that involve rewriting history or transferring data between repositories. The command examines the reachability of objects from the commits, tags, and branches, and reports any inconsistencies. It's often run during operations like `git receive-pack` (server-side) and can be triggered manually to proactively identify potential problems.

CAVEATS

Running git fsck can be time-consuming on large repositories. Using the `--connectivity-only` option can significantly speed up the process if you're primarily concerned with connectivity issues. If corruption is detected, it's essential to have backups or be prepared to repair the repository. Automatic repair is often not possible and manual intervention might be necessary.

EXIT STATUS

The command exits with 0 if everything is OK, and 1 if something is wrong.

SEE ALSO

Copied to clipboard