Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Maintenance and Recovery

git multi-pack-index command

Reference for git multi-pack-index: write, verify, expire and repack subcommands, how a MIDX file speeds up lookups across packs, and bitmaps with --bitmap.

A packfile comes with its own index (.idx), and to find an object Git may have to consult the index of every pack in turn. In a repository with dozens of packs, as happens after many fetches, that adds up. A multi-pack-index (MIDX) is a single file, .git/objects/pack/multi-pack-index, that lists the objects of many packs together and says which pack and offset holds each one.

git multi-pack-index writes and verifies that file, removes packs that the MIDX has made redundant (expire), and can combine small packs into a bigger one (repack). It is a performance tool: object contents and IDs are never affected.

Terminal
git multi-pack-index write
git multi-pack-index verify

Try it

Bash Write a MIDX over two packs

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 Repack small packs through the MIDX

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 multi-pack-index [--object-dir=<dir>] [--[no-]progress] <subcommand>

git multi-pack-index write  [--preferred-pack=<pack>] [--[no-]bitmap]
                            [--stdin-packs] [--refs-snapshot=<path>]
git multi-pack-index verify
git multi-pack-index expire
git multi-pack-index repack [--batch-size=<size>]
Name Description
write Create or update the multi-pack-index file from the packs currently in the object directory.
verify Check the MIDX and compare it with the pack indexes.
expire Delete packs whose objects are all provided by other packs listed in the MIDX, then rewrite the MIDX without them.
repack Create a new pack from the objects of the smaller packs, chosen to reach --batch-size, and update the MIDX.
--batch-size=<size> Target size in bytes for the new pack. Without it (or with 0) the command selects all packs except the largest.
--preferred-pack=<pack> When an object appears in several packs, prefer this one; for bitmaps it determines which objects come first.
--bitmap / --no-bitmap Write (or skip) a multi-pack bitmap, which makes counting and listing reachable objects fast.
--stdin-packs Read pack names from standard input and include only those packs.
--object-dir=<dir> Operate on this object directory, such as an alternate.

Returns: nothing on success. verify exits non-zero when the file does not match the packs.

Edge cases: if a pack named in the MIDX disappears (for example through git gc), Git notices and ignores the stale MIDX; running write again fixes it. repack and expire only consider packs that are listed in the current MIDX, and packs marked with a .keep file are never deleted.

Usage notes

  • Why bother. Object lookup is a binary search in one table instead of one per pack, and a MIDX bitmap lets Git answer reachability questions for fetch and rev-list --objects much faster. Hosting servers benefit most.
  • Automatic upkeep. git maintenance run --task=incremental-repack uses write, expire and repack as a background alternative to git gc, which would rewrite the whole history into one pack. Config: core.multiPackIndex (read the file, default true), repack.writeBitmaps, pack.writeBitmapLookupTable.
  • Not a replacement for repack. A MIDX does not merge packs or create deltas across packs. Use git repack for that.
  • Verification is cheap. verify reads the file and cross-checks offsets, so you can run it in a health check next to git fsck.
  • Compatibility. Older Git versions ignore the file. Dumb HTTP servers do not serve it.
  • Safety. expire and repack change which files exist under .git/objects/pack. Do not run them while another Git process is writing to the same repository.