LinuxCommandLibrary

git-pack-objects

Create a packed archive of Git objects

SYNOPSIS

git pack-objects [options...] <base-object-id> [<pack-file>]

PARAMETERS

--all-progress
    Show progress for all pack-objects invocations in a session.

--all-progress-implied
    Imply --all-progress if --progress is used.

--allow-empty
    Allow creating an empty pack.

--allow-pack-reuse
    Permit reusing existing packs.

--check-self-contained-and-connected
    Verify pack is self-contained and connected.

--compression-level
    Set zlib compression level (1-9, default 6).

--continue
    Continue packing after interruption.

--depth <n>
    Maximum delta depth (default 50).

--delta-base-offset
    Use negative offsets in delta objects.

--delta-island=<group>
    Pack island deltas for specified group.

--evict-on-spill
    Evict objects from memory on spill.

--exec=<cmd>
    Command to run before packing each object.

--format=<format>
    Output format (default 'pack').

--housekeeping-size=<size>
    Minimum housekeeping size in MiB.

--ignore-missing-links
    Ignore missing objects in thin packs.

--incremental
    Ignore pack .keep files.

--index-version=<version>
    .idx file version (2 or 3).

--input=<file>
    Read objects from file instead of stdin.

--keep-empty
    Keep empty packs.

--keep-true-parents
    Retain true parent info for shallow clones.

--local
    Ignore objects in alternate object stores.

--max-pack-size=<n>
    Maximum pack size in bytes.

--no-clone-bundle
    Disable clone bundle features.

--no-progress
    Disable progress meter.

--no-reuse-delta
    Don't reuse existing deltas.

--no-reuse-object
    Don't reuse existing objects.

--no-update-server-info
    Skip updating server info.

--non-empty
    Fail if no objects to pack.

--nothing-new
    Fail if new objects found.

--object-dir=<dir>
    Object database directory.

--pack-keep-file <file>
    Create .keep file from list.

--progress
    Show progress meter.

--quiet
    Be quiet.

--reuse-delta=<what>
    Reuse deltas if possible.

--reuse-object
    Reuse existing objects.

--shallow <object>
    Treat specified objects as shallow.

--shallow-since=<time>
    Shallow objects older than time.

--stats
    Print packing statistics.

--stdout
    Write pack to stdout.

--threads=<n>
    Number of threads (default varies).

--thin
    Create thin pack without complete bases.

--unpacked=<object>
    Objects already in pack.

--use-bitmap-index
    Use bitmap index for reachability.

--window=<n>
    Limit objects considered for deltas (default 10).

--write-reverse-index
    Write reverse index file.

DESCRIPTION

git pack-objects is a low-level "plumbing" command in Git that generates packfiles, which are highly efficient binary archives of Git objects such as blobs, trees, commits, and tags. Packfiles use delta compression to store objects as differences from similar "base" objects, dramatically reducing repository size.

This command is not intended for direct end-user invocation but is called internally by higher-level commands like git repack, git push, and git fetch. It reads a list of objects to pack (from stdin or arguments), optionally resolves revisions, and outputs a packfile (.git/objects/pack/pack-XXXXXX) along with an optional index (.git/objects/pack/pack-XXXXXX.idx).

Key features include multi-threaded packing, adjustable compression levels, thin packs for network transfer (which omit common bases assuming the receiver has them), and reuse of existing deltas or objects to speed up repacking. The command sorts objects topologically for optimal delta bases, using parameters like --window and --depth to control search scope.

Usage typically involves piping revision lists via git rev-list, e.g., git rev-list --objects --all | git pack-objects --stdout --progress. It supports progress reporting and statistics output for monitoring large operations.

CAVEATS

Internal plumbing command; direct use can corrupt repositories if misused. Requires write access to .git/objects/pack/. Thin packs need compatible receiver. High memory usage for large repos; use --threads and --window to tune.

PACKFILE FORMAT

Packfiles start with header (signature 'PACK', version 2/3, object count), followed by object data (type, size, compressed content or delta). Indexed by .idx for fast lookup.

DELTA COMPRESSION

Finds similar base objects within --window limit and --depth; stores difference. Supports copy instructions for efficiency. Thin packs defer bases to receiver.

HISTORY

Introduced in Git 1.0 (2005) as core packing mechanism by Linus Torvalds and contributors. Evolved with delta compression (v1.1), multi-threading (v1.7.11), bitmaps (v1.7.1), and reverse indexes (v2.19). Key for efficient Git storage and transfer.

SEE ALSO

Copied to clipboard