Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git pack-objects command

Reference for git pack-objects: build a packfile from a list of object IDs, with --revs, --stdout, --window, --depth, --thin and delta compression notes.

git pack-objects reads a list of objects and writes them into a packfile: one compact file in which similar objects are stored as deltas against each other. It also writes the matching .idx index. Packfiles are what git gc, git repack, git push and git fetch are built on, and pack-objects is the engine behind all of them.

You rarely call it by hand, but it is the best way to see how packing works. You feed it object names (one per line) on standard input, give it a base name for the output files, and it prints the checksum that becomes part of the file name.

Terminal
git rev-list --objects --all | git pack-objects <base-name>
git pack-objects --revs --stdout < revs.txt > out.pack

Try it

Bash Pack every object into one 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 Stream a pack to standard output

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 pack-objects [options] <base-name> < <object-list>
git pack-objects [options] --stdout < <object-list> > file.pack
git pack-objects --revs [options] <base-name> < <rev-list-arguments>
Name Description
<base-name> Prefix for the output. Git writes <base-name>-<hash>.pack and <base-name>-<hash>.idx, and prints <hash> (the pack checksum) on standard output.
--stdout Write the pack to standard output instead of files; no index is written.
--revs Read revision arguments (HEAD, ^base, --all) rather than object IDs, and pack what rev-list --objects would list.
--all With --revs, include every ref.
--window=<n>, --depth=<n> How many neighbours to try as delta bases (default 10) and the maximum delta chain length (default 50).
--thin Allow deltas against objects that are not in the pack. Used with --stdout; the receiver must complete the pack (index-pack --fix-thin).
--delta-base-offset Store delta bases by offset, which is smaller. Both sides need to support it.
--incremental Skip objects that already exist in some pack.
--no-reuse-delta, --no-reuse-object Recompute deltas or compression instead of reusing what is stored. Slower, sometimes smaller.
--threads=<n> Threads for delta search. Use 1 for reproducible output.
-q, --progress Silence or force progress output.

Exit status: 0 on success; nonzero if an object ID cannot be found or output cannot be written.

Edge cases: an ID that does not exist makes the command fail with a "bad object" message. Feeding a path after the object name (as rev-list --objects does) is fine: the path is used only as a hint for choosing delta partners.

Usage notes

  • Why the path matters. rev-list --objects prints <id> <path>. Git sorts objects by type, name and size, then compares each blob with its neighbours; the path groups different versions of one file, which is what makes deltas small.
  • A pack is not a snapshot of a branch. It is only a set of objects. Nothing in it says which commit is the tip; refs live outside.
  • Thin packs. git push and git fetch send thin packs: a commit that changes one line sends a delta against a blob the other side already has. A thin pack on disk would be broken, so receivers fix it with git index-pack.
  • Output is deterministic only with one thread. Several threads may pick different delta bases, so the checksum can differ between runs.
  • git repack is the friendly wrapper. It calls pack-objects with the right options and then removes redundant packs. Use pack-objects directly only for experiments, custom transport or tooling.
  • Pack size limits. --max-pack-size splits output across several packs; --window-memory caps memory used during the delta search.