Check Git Pack Files Safely with git verify-pack
You will finish with a repeatable way to check a Git pack index and its matching pack file, inspect the objects inside it, and read the delta-chain histogram. The examples use Git 2.43.0 and its installed git-man package, version 1:2.43.0-1ubuntu7.3. Allow about ten minutes if you already know which pack you need to examine.
The route
Jump straight to the step you need, or tick off Done means at the end.
This is a read-only diagnostic workflow. You need a shell and access to a Git repository or a directory containing a pack index. No command here needs sudo. Do not run a verifier on an untrusted repository while assuming that validation makes the repository safe to use elsewhere.
1. Locate the index file
git verify-pack takes one or more .idx files. It then reads the corresponding pack file, so pass the index rather than the .pack file. In a normal repository, list the object packs without changing anything:
$ find .git/objects/pack -maxdepth 1 -type f -name '*.idx' -print
.git/objects/pack/pack-EXAMPLE.idx
Replace pack-EXAMPLE.idx with the real name printed on your machine. The index and pack normally share the same name and differ only in the suffix. Check both paths before continuing:
$ test -r .git/objects/pack/pack-EXAMPLE.idx && echo index-readable
$ test -r .git/objects/pack/pack-EXAMPLE.pack && echo pack-readable
index-readable
pack-readable
Checkpoint: you should have a readable pair of files with one common pack name. If the second test fails, stop and investigate a missing or inaccessible pack rather than treating the index alone as a complete archive.
2. Run the ordinary integrity check
Pass the index to the command without options:
$ git verify-pack .git/objects/pack/pack-EXAMPLE.idx
non delta: 6 objects
The exact count and the presence of a delta line depend on the repository. A zero exit status is the useful machine-checkable result. Capture it when scripting:
$ if git verify-pack .git/objects/pack/pack-EXAMPLE.idx; then
> echo 'pack verification passed'
> else
> echo 'pack verification failed' >&2
> exit 1
> fi
non delta: 6 objects
pack verification passed
The command validates the index and the corresponding pack contents. It does not repair either file, repack the repository or alter references. A failure is evidence to preserve: save the diagnostic output and work from a copy before attempting any later repair operation.
3. Inspect the object list
Add -v, or its long form --verbose, when you need the objects and their locations:
$ git verify-pack --verbose .git/objects/pack/pack-EXAMPLE.idx
OBJECT_ID type size size-in-packfile offset-in-packfile
3257a0eec215eca91b3ede192347748e53428602 commit 206 145 12
a471f56364c4a1c4cac626599d54437a286ddddf commit 158 116 157
814f4a422927b82f5f8a43f8fab6d3839e3983f2 blob 8 17 273
The first field is the object ID. The next fields identify its type, uncompressed size, size in the pack and offset. The manual describes a further depth and base-object-id pair for deltified objects. Real IDs, counts and ordering vary, so use the output as evidence about this pack rather than copying these values into a script.
For a large pack, keep the report in a file and search it with ordinary read-only tools:
$ git verify-pack -v .git/objects/pack/pack-EXAMPLE.idx > /tmp/verify-pack-report.txt
$ sed -n '1,12p' /tmp/verify-pack-report.txt
4. Read delta-chain statistics
Use -s or --stat-only when you want the histogram without verifying pack contents:
$ git verify-pack --stat-only .git/objects/pack/pack-EXAMPLE.idx
non delta: 6 objects
chain length = 1: 2 objects
The lines are repository-specific. This mode is for inspecting delta-chain lengths, not for replacing the ordinary integrity check. With both flags, Git prints the object list as well as the histogram:
$ git verify-pack --stat-only --verbose .git/objects/pack/pack-EXAMPLE.idx
3257a0eec215eca91b3ede192347748e53428602 commit 206 145 12
non delta: 6 objects
Do not infer a damaged pack from an unusual histogram alone. Re-run the plain command and check its exit status before investigating performance or storage layout.
5. Handle awkward file names and failures
If a path begins with a hyphen, put -- before the index argument. This tells Git to stop interpreting later arguments as options:
$ git verify-pack -- ./pack-EXAMPLE.idx
Quote paths containing spaces or shell metacharacters. Avoid parsing the verbose report by fixed column widths: a future object type or output detail can make that brittle. For automation, check the exit status and treat the text as a diagnostic report.
If Git reports that it cannot open an index or its pack, confirm the path and permissions:
$ ls -l .git/objects/pack/pack-EXAMPLE.idx .git/objects/pack/pack-EXAMPLE.pack
$ git rev-parse --git-dir
If verification reports corruption, do not delete the files or run an automatic cleanup as a first response. Preserve the repository, record the exact command and error, and compare a fresh copy or a known-good clone. A replacement pack, repack or recovery from another clone changes repository state and needs its own backup and review.
Done means
- You passed a readable
.idxfile, not just a pack filename. - The plain command returned success and its output was recorded when needed.
- You used
-vfor object details or-sfor statistics with the correct expectation of what each mode verifies. - The repository and pack files remain unchanged.
- Any reported failure has been preserved for recovery work instead of being hidden by cleanup.