Git show-index: Inspect Pack Indexes
Inspect Git pack index entries directly with git show-index, understand its output and hash-format option, and distinguish index inspection from index creation and pack verification.
Advanced
What `git show-index` reads
A Git pack has an accompanying index file. `git show-index` reads that `.idx` file from standard input and prints the entries it contains. It inspects the index itself; it does not unpack the pack or verify the complete pack contents.
git show-index < .git/objects/pack/pack-<id>.idxQuick check
What input does `git show-index` consume?
Understand the output
For a version-2-or-newer index, each output line contains the object offset in the corresponding pack, the object ID, and the CRC32 of the object data. The entries are emitted in the order found in the index, which for a correctly constructed index is sorted by object ID.
git show-index < .git/objects/pack/pack-<id>.idx | headQuick check
In the normal index output, what does the first column represent?
Use the object-format option
`--object-format=<hash-algorithm>` tells `git show-index` which object format the index uses. The documented values are `sha1` and, when enabled, `sha256`. Without the option, Git uses the current repository format, or SHA-1 outside a repository when no other format is specified.
git show-index --object-format=sha1 < .git/objects/pack/pack-<id>.idxQuick check
What does `--object-format=sha1` identify?
Show-index versus verify-pack
`git show-index` is deliberately narrow: it considers the index file itself. `git verify-pack` analyzes the pack/index pair and can provide information about the packed objects and their relationships. Use `show-index` when you need to inspect index entries directly, not as a replacement for pack verification.
git show-index < .git/objects/pack/pack-<id>.idx
git verify-pack -v .git/objects/pack/pack-<id>.idxQuick check
Why is `git show-index` not a replacement for `git verify-pack`?
How it fits with index-pack
`git index-pack` creates an index for an existing pack. Once an `.idx` exists, `git show-index` can read that index and expose its entries. Keeping these responsibilities separate prevents confusing index construction with index inspection.
git index-pack --rev-index .git/objects/pack/pack-<id>.pack
git show-index < .git/objects/pack/pack-<id>.idxQuick check
Which command creates the `.idx` file for an existing `.pack`?
Practice what you learned
Use the dedicated Git code-completion exercise for this lesson.
Key takeaways
`git show-index` is an index-inspection plumbing command. It reads an `.idx` file from standard input, reports indexed object offsets and IDs (and CRC32 for index version 2 or newer), and can be told the hash format explicitly. It is narrower than `git verify-pack` and complementary to `git index-pack`.
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.