Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git index-pack command

Reference for git index-pack: create the .idx file for a packfile, read a pack from stdin, fix thin packs with --fix-thin and verify objects with --strict.

git index-pack reads a packfile, works out where every object starts, resolves deltas, checks the checksums, and writes the .idx file that lets Git find an object inside the pack quickly. A .pack without its .idx is unusable, so every fetch and clone ends with this step.

It has two main modes. Given a file name, it indexes a pack that is already on disk. With --stdin it reads a pack from a pipe, saves it into the repository's objects/pack directory and indexes it at the same time, which is what git fetch does with the data from the server.

Terminal
git index-pack <file>.pack
git index-pack --stdin [--fix-thin] [--keep] < incoming.pack

Try it

Bash Index a pack file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Receive a pack on standard input

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git index-pack [-v] [-o <index-file>] <pack-file>
git index-pack --stdin [--fix-thin] [--keep[=<msg>]] [--strict] [--check-self-contained-and-connected]
git index-pack --verify <pack-file>
Name Description
<pack-file> The .pack to index. The index is written next to it with the extension .idx.
-o <index-file> Write the index to this path instead.
--stdin Read the pack from standard input and store it under objects/pack of the current repository. Prints pack<TAB><hash> (or keep<TAB><hash> with --keep).
--fix-thin Complete a thin pack by appending the missing delta bases from the repository. Only valid with --stdin.
--keep[=<msg>] Create a .keep file so git gc leaves the pack alone until the caller removes it.
--strict Also check that every object is well formed and that links point to objects that exist.
--verify Re-read an existing pack and index, and check the pack against them without writing.
-v, --verify-stat Show progress or statistics.
--object-format=<fmt> Hash algorithm of the pack when it cannot be detected (SHA-1 or SHA-256).
--threads=<n> Threads used when resolving deltas.

Output: without --stdin, the pack checksum (a 40-character hash for SHA-1 repositories) is printed.

Errors: a damaged pack (bad checksum, truncated data, wrong header) stops with fatal: ... and a nonzero status, and no index is written. A thin pack given without --fix-thin fails with an "unresolved deltas" message.

Usage notes

  • File name. A pack named pack-<hash>.pack pairs with pack-<hash>.idx; the hash is the checksum printed by index-pack itself. Indexing a differently named file works but is unusual.
  • Thin packs only arrive through transport. --fix-thin makes them self-contained by adding the bases, so the stored pack is slightly larger than what you received.
  • Verification. index-pack checks the checksum of every object, so --stdin is also an integrity check of data from the network. Set transfer.fsckObjects to add the --strict checks on fetch.
  • Small packs. git fetch unpacks fewer than transfer.unpackLimit (100 by default) objects into loose files with git unpack-objects instead of keeping a pack.
  • Not the same as verify-pack. git verify-pack inspects an existing index and prints the contents; index-pack creates it.
  • Reftable and multi-pack indexes are separate structures: multi-pack-index sits above many .idx files and does not replace them.