LinuxCommandLibrary

git-verify-pack

Verify the integrity of packfiles

TLDR

Verify a packed Git archive file

$ git verify-pack [path/to/pack-file]
copy

Verify a packed Git archive file and show verbose details
$ git verify-pack [[-v|--verbose]] [path/to/pack-file]
copy

Verify a packed Git archive file and only display the statistics
$ git verify-pack [[-s|--stat-only]] [path/to/pack-file]
copy

SYNOPSIS

git verify-pack [--verbose | -v] [--stat-only | -s] <pack-file> [<pack-file> ...]

PARAMETERS

--verbose | -v
    Show a detailed list of all objects, their sizes, and types. Also reports statistics like the number of objects, deltas, and loose objects. This provides the most comprehensive output.

--stat-only | -s
    Only show statistics about the pack file, without listing individual objects. This option is faster for very large pack files when only a summary is needed.

<pack-file>
    The path to the pack file (.pack extension) to be verified. Multiple pack files can be specified to verify them all in one invocation. These files are typically found in .git/objects/pack/.

DESCRIPTION

git-verify-pack is a Git plumbing command used to check the validity and consistency of a Git pack file and its corresponding index. Pack files are an efficient way Git stores objects (blobs, trees, commits, tags) by compressing them and delta-compressing similar objects. This command is crucial for ensuring data integrity, especially after network transfers or disk operations.

It reads the pack file, decompresses objects, verifies checksums (both object and pack checksums), and checks for consistency between the pack file and its .idx (index) file. Any inconsistencies, such as corrupted objects, incorrect sizes, or missing objects, are reported. It's often used by developers and system administrators for diagnostic purposes or as part of a robust backup strategy to confirm repository health. It helps identify potential data corruption before it leads to more severe issues within a Git repository.

CAVEATS

This command operates directly on pack files and their indices; it is not a user-level command for general repository health checks like git fsck. It only reports corruption and does not attempt to fix it. Verifying very large pack files can be time-consuming and memory-intensive, especially with the --verbose option. It requires both the .pack and its corresponding .idx file to be present and correctly named (e.g., pack-abc.pack and pack-abc.idx).

RETURN STATUS

git-verify-pack exits with a non-zero status code if any errors or inconsistencies are found during the verification process. It exits with zero status on success. This behavior makes it highly suitable for use in scripts to programmatically check pack file health.

OUTPUT FORMAT

The command's output typically includes the pack file version, total number of objects, number of loose objects, number of delta objects, and various checksums (pack checksum, object checksums). When the --verbose option is used, it lists each object's type (e.g., blob, commit), its uncompressed size, and its offset within the pack file.

HISTORY

Pack files and their verification mechanisms have been fundamental to Git's object storage model since its early days. The git-verify-pack command likely emerged as a core utility alongside the introduction of pack files to ensure the integrity of this optimized storage format. Its purpose has remained consistent: to provide a low-level diagnostic tool for validating the raw pack file data. It's a plumbing command, meaning it's intended for scripting and lower-level operations rather than direct daily use by end-users, reflecting its foundational role in Git's internal object database management.

SEE ALSO

git fsck(1), git pack-objects(1), git index-pack(1), git repack(1), git cat-file(1)

Copied to clipboard