git show-index turns a Git pack .idx file into a plain list of object offsets, IDs and CRCs, read straight off standard input. It is a read-only way to identify each object in the index and relate its pack offset to the corresponding packfile. The examples use Git 2.43.0 from the installed git-man package version 1:2.43.0-1ubuntu7.3.
Allow about ten minutes. You need Git and read access to the repository or pack directory. The command reads an index from standard input. It does not open a repository by itself, repair an index, rewrite a packfile or change Git objects. No elevated privileges are normally required.
Confirm the executable and the local interface before building a diagnostic around it:
$ git --version
git version 2.43.0
$ git show-index -h
usage: git show-index [--object-format=<hash-algorithm>]
The unusual part of the interface is the input contract: give git show-index the contents of a pack index on standard input. Passing the path as a positional argument is not the documented form.
Checkpoint: if git show-index -h reports a different option set, use that installed help as the final word for your host. This guide describes the Git 2.43.0 behaviour installed here.
A normal repository keeps packfiles and their indexes together under .git/objects/pack/. List both sides of the pair:
$ find .git/objects/pack -maxdepth 1 -type f \( -name '*.idx' -o -name '*.pack' \) -print
.git/objects/pack/pack-OBJECTS.idx
.git/objects/pack/pack-OBJECTS.pack
The hexadecimal name is a placeholder in this output. The real .idx and .pack files must have the same pack name. If the directory is empty, the repository may have only loose objects, or its packs may be stored elsewhere. Do not manufacture an index file.
For a quick read-only check, select an index explicitly and compare its basename with the packfile:
$ idx='.git/objects/pack/pack-OBJECTS.idx'
$ pack="${idx%.idx}.pack"
$ test -r "$idx" && test -r "$pack" && printf 'matching readable pair\n'
matching readable pair
Replace pack-OBJECTS.idx with a name that exists on your machine. The test command only checks permissions and names. It does not validate the pack.
Run the command with shell redirection:
$ git show-index < "$idx"
346 3ab2e03dea1bc23d0ef6715fd6395ce1629f1889 (976f5840)
277 66a52ee7a1d803dc57859c3e95ac9dcdc87c0164 (10f89e7a)
12 7f05843430b31095ef1e08894c11c4662eea0cb2 (e011bc78)
158 88241c3faafe6aeb62833587ab902c764cabb8bc (c0965621)
Your values and line count will differ. Each line describes one object in the order found in the index. In a correctly constructed index, that order should be sorted by object ID, not by pack offset.
Read the columns as follows:
.pack file.The offset is not a line number and is not a byte position in the .idx file. Use it with the matching packfile only.
For a count or a simple ordering check, keep the output in a shell pipeline:
$ git show-index < "$idx" | tee /tmp/pack-index.txt | wc -l
6
The temporary file contains the dump and can be inspected with ordinary read-only tools:
$ sed -n '1,3p' /tmp/pack-index.txt
346 3ab2e03dea1bc23d0ef6715fd6395ce1629f1889 (976f5840)
277 66a52ee7a1d803dc57859c3e95ac9dcdc87c0164 (10f89e7a)
12 7f05843430b31095ef1e08894c11c4662eea0cb2 (e011bc78)
The command's normal output is suitable for scripts, but do not parse the third column as an object ID. It is a parenthesised CRC32 value. Also avoid assuming that every index has three columns: older index formats may omit the CRC column.
Checkpoint: a successful command with no output can be valid for an empty index, but a non-zero status usually means the input was not a readable or recognised index. Preserve the status in a script:
if git show-index < "$idx" > /tmp/pack-index.txt; then
printf 'index read successfully\n'
else
status=$?
printf 'git show-index failed with status %s\n' "$status" >&2
exit "$status"
fi
git show-index deliberately considers the index file alone. If you need pack-level information, use the matching index with git verify-pack:
$ git verify-pack -v "$idx" | sed -n '1,8p'
7f05843430b31095ef1e08894c11c4662eea0cb2 commit 213 146 12
88241c3faafe6aeb62833587ab902c764cabb8bc commit 166 119 158
66a52ee7a1d803dc57859c3e95ac9dcdc87c0164 blob 13 22 277
non delta: 6 objects
...: ok
The exact object rows and summary depend on the pack. Notice that verify-pack reports object type and compressed sizes as well as offsets, while show-index exposes the index's offsets, IDs and, on newer indexes, CRC values. Use the lighter command when you only need index contents.
Do not run either command with sudo as a first response to confusing output. First check that idx names the intended file and that its companion pack exists. Use elevated privileges only when your administrator has deliberately granted access to a protected repository; privilege does not repair a mismatched or corrupt pair.
The installed command accepts --object-format=sha1 and, when enabled, --object-format=sha256. Outside a repository the default is SHA-1. Inside a repository the default follows its extensions.objectFormat setting:
$ git show-index --object-format=sha1 < "$idx" | sed -n '1p'
346 3ab2e03dea1bc23d0ef6715fd6395ce1629f1889 (976f5840)
Specify the algorithm when inspecting an index outside its repository or when a script must be explicit. Do not use SHA-1 merely because its object IDs are familiar. SHA-256 and SHA-1 repositories are not interoperable in the current behaviour documented by Git, so use the format that belongs to the index.
.idx and its same-named .pack companion.git verify-pack -v is the better diagnostic.