<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="git-pack-objects(1)">
    <title>git-pack-objects(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-pack-objects(1)</primary>
</indexterm>
<simplesect id="git-pack-objects(1)__name">
<title>NAME</title>
<simpara>git-pack-objects - Create a packed archive of objects</simpara>
</simplesect>
<simplesect id="git-pack-objects(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git pack-objects</emphasis> [-q | --progress | --all-progress] [--all-progress-implied]
        [--no-reuse-delta] [--delta-base-offset] [--non-empty]
        [--local] [--incremental] [--window=&lt;n&gt;] [--depth=&lt;n&gt;]
        [--revs [--unpacked | --all]] [--keep-pack=&lt;pack-name&gt;]
        [--cruft] [--cruft-expiration=&lt;time&gt;]
        [--stdout [--filter=&lt;filter-spec&gt;] | &lt;base-name&gt;]
        [--shallow] [--keep-true-parents] [--[no-]sparse] &lt; &lt;object-list&gt;</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-pack-objects(1)__description">
<title>DESCRIPTION</title>
<simpara>Reads list of objects from the standard input, and writes either one or
more packed archives with the specified base-name to disk, or a packed
archive to the standard output.</simpara>
<simpara>A packed archive is an efficient way to transfer a set of objects
between two repositories as well as an access efficient archival
format.  In a packed archive, an object is either stored as a
compressed whole or as a difference from some other object.
The latter is often called a delta.</simpara>
<simpara>The packed archive format (.pack) is designed to be self-contained
so that it can be unpacked without any further information. Therefore,
each object that a delta depends upon must be present within the pack.</simpara>
<simpara>A pack index file (.idx) is generated for fast, random access to the
objects in the pack. Placing both the index file (.idx) and the packed
archive (.pack) in the pack/ subdirectory of $GIT_OBJECT_DIRECTORY (or
any of the directories on $GIT_ALTERNATE_OBJECT_DIRECTORIES)
enables Git to read from the pack archive.</simpara>
<simpara>The <emphasis>git unpack-objects</emphasis> command can read the packed archive and
expand the objects contained in the pack into "one-file
one-object" format; this is typically done by the smart-pull
commands when a pack is created on-the-fly for efficient network
transport by their peers.</simpara>
</simplesect>
<simplesect id="git-pack-objects(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
base-name
</term>
<listitem>
<simpara>
        Write into pairs of files (.pack and .idx), using
        &lt;base-name&gt; to determine the name of the created file.
        When this option is used, the two files in a pair are written in
        &lt;base-name&gt;-&lt;SHA-1&gt;.{pack,idx} files.  &lt;SHA-1&gt; is a hash
        based on the pack content and is written to the standard
        output of the command.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stdout
</term>
<listitem>
<simpara>
        Write the pack contents (what would have been written to
        .pack file) out to the standard output.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--revs
</term>
<listitem>
<simpara>
        Read the revision arguments from the standard input, instead of
        individual object names.  The revision arguments are processed
        the same way as <emphasis>git rev-list</emphasis> with the <emphasis>--objects</emphasis> flag
        uses its <emphasis>commit</emphasis> arguments to build the list of objects it
        outputs.  The objects on the resulting list are packed.
        Besides revisions, <emphasis>--not</emphasis> or <emphasis>--shallow &lt;SHA-1&gt;</emphasis> lines are
        also accepted.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unpacked
</term>
<listitem>
<simpara>
        This implies <emphasis>--revs</emphasis>.  When processing the list of
        revision arguments read from the standard input, limit
        the objects packed to those that are not already packed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--all
</term>
<listitem>
<simpara>
        This implies <emphasis>--revs</emphasis>.  In addition to the list of
        revision arguments read from the standard input, pretend
        as if all refs under <emphasis>refs/</emphasis> are specified to be
        included.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--include-tag
</term>
<listitem>
<simpara>
        Include unasked-for annotated tags if the object they
        reference was included in the resulting packfile.  This
        can be useful to send new tags to native Git clients.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stdin-packs
</term>
<listitem>
<simpara>
        Read the basenames of packfiles (e.g., <emphasis>pack-1234abcd.pack</emphasis>)
        from the standard input, instead of object names or revision
        arguments. The resulting pack contains all objects listed in the
        included packs (those not beginning with <emphasis>^</emphasis>), excluding any
        objects listed in the excluded packs (beginning with <emphasis>^</emphasis>).
</simpara>
<simpara>Incompatible with <emphasis>--revs</emphasis>, or options that imply <emphasis>--revs</emphasis> (such as
<emphasis>--all</emphasis>), with the exception of <emphasis>--unpacked</emphasis>, which is compatible.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cruft
</term>
<listitem>
<simpara>
        Packs unreachable objects into a separate "cruft" pack, denoted
        by the existence of a <emphasis>.mtimes</emphasis> file. Typically used by <emphasis>git
        repack --cruft</emphasis>. Callers provide a list of pack names and
        indicate which packs will remain in the repository, along with
        which packs will be deleted (indicated by the <emphasis>-</emphasis> prefix). The
        contents of the cruft pack are all objects not contained in the
        surviving packs which have not exceeded the grace period (see
        <emphasis>--cruft-expiration</emphasis> below), or which have exceeded the grace
        period, but are reachable from an other object which hasn't.
</simpara>
<simpara>When the input lists a pack containing all reachable objects (and lists
all other packs as pending deletion), the corresponding cruft pack will
contain all unreachable objects (with mtime newer than the
<emphasis>--cruft-expiration</emphasis>) along with any unreachable objects whose mtime is
older than the <emphasis>--cruft-expiration</emphasis>, but are reachable from an
unreachable object whose mtime is newer than the <emphasis>--cruft-expiration</emphasis>).</simpara>
<simpara>Incompatible with <emphasis>--unpack-unreachable</emphasis>, <emphasis>--keep-unreachable</emphasis>,
<emphasis>--pack-loose-unreachable</emphasis>, <emphasis>--stdin-packs</emphasis>, as well as any other
options which imply <emphasis>--revs</emphasis>.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cruft-expiration=&lt;approxidate&gt;
</term>
<listitem>
<simpara>
        If specified, objects are eliminated from the cruft pack if they
        have an mtime older than <emphasis>&lt;approxidate&gt;</emphasis>. If unspecified (and
        given <emphasis>--cruft</emphasis>), then no objects are eliminated.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--window=&lt;n&gt;
</term>
<term>
--depth=&lt;n&gt;
</term>
<listitem>
<simpara>
        These two options affect how the objects contained in
        the pack are stored using delta compression.  The
        objects are first internally sorted by type, size and
        optionally names and compared against the other objects
        within --window to see if using delta compression saves
        space.  --depth limits the maximum delta depth; making
        it too deep affects the performance on the unpacker
        side, because delta data needs to be applied that many
        times to get to the necessary object.
</simpara>
<simpara>The default value for --window is 10 and --depth is 50. The maximum
depth is 4095.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--window-memory=&lt;n&gt;
</term>
<listitem>
<simpara>
        This option provides an additional limit on top of <emphasis>--window</emphasis>;
        the window size will dynamically scale down so as to not take
        up more than <emphasis>&lt;n&gt;</emphasis> bytes in memory.  This is useful in
        repositories with a mix of large and small objects to not run
        out of memory with a large window, but still be able to take
        advantage of the large window for the smaller objects.  The
        size can be suffixed with "k", "m", or "g".
        <emphasis>--window-memory=0</emphasis> makes memory usage unlimited.  The default
        is taken from the <emphasis>pack.windowMemory</emphasis> configuration variable.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--max-pack-size=&lt;n&gt;
</term>
<listitem>
<simpara>
        In unusual scenarios, you may not be able to create files
        larger than a certain size on your filesystem, and this option
        can be used to tell the command to split the output packfile
        into multiple independent packfiles, each not larger than the
        given size. The size can be suffixed with
        "k", "m", or "g". The minimum size allowed is limited to 1 MiB.
        The default is unlimited, unless the config variable
        <emphasis>pack.packSizeLimit</emphasis> is set. Note that this option may result in
        a larger and slower repository; see the discussion in
        <emphasis>pack.packSizeLimit</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--honor-pack-keep
</term>
<listitem>
<simpara>
        This flag causes an object already in a local pack that
        has a .keep file to be ignored, even if it would have
        otherwise been packed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--keep-pack=&lt;pack-name&gt;
</term>
<listitem>
<simpara>
        This flag causes an object already in the given pack to be
        ignored, even if it would have otherwise been
        packed. <emphasis>&lt;pack-name&gt;</emphasis> is the pack file name without
        leading directory (e.g. <emphasis>pack-123.pack</emphasis>). The option could be
        specified multiple times to keep multiple packs.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--incremental
</term>
<listitem>
<simpara>
        This flag causes an object already in a pack to be ignored
        even if it would have otherwise been packed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--local
</term>
<listitem>
<simpara>
        This flag causes an object that is borrowed from an alternate
        object store to be ignored even if it would have otherwise been
        packed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--non-empty
</term>
<listitem>
<simpara>
        Only create a packed archive if it would contain at
        least one object.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--progress
</term>
<listitem>
<simpara>
        Progress status is reported on the standard error stream
        by default when it is attached to a terminal, unless -q
        is specified. This flag forces progress status even if
        the standard error stream is not directed to a terminal.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--all-progress
</term>
<listitem>
<simpara>
        When --stdout is specified then progress report is
        displayed during the object count and compression phases
        but inhibited during the write-out phase. The reason is
        that in some cases the output stream is directly linked
        to another command which may wish to display progress
        status of its own as it processes incoming pack data.
        This flag is like --progress except that it forces progress
        report for the write-out phase as well even if --stdout is
        used.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--all-progress-implied
</term>
<listitem>
<simpara>
        This is used to imply --all-progress whenever progress display
        is activated.  Unlike --all-progress this flag doesn't actually
        force any progress display by itself.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-q
</term>
<listitem>
<simpara>
        This flag makes the command not to report its progress
        on the standard error stream.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-reuse-delta
</term>
<listitem>
<simpara>
        When creating a packed archive in a repository that
        has existing packs, the command reuses existing deltas.
        This sometimes results in a slightly suboptimal pack.
        This flag tells the command not to reuse existing deltas
        but compute them from scratch.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-reuse-object
</term>
<listitem>
<simpara>
        This flag tells the command not to reuse existing object data at all,
        including non deltified object, forcing recompression of everything.
        This implies --no-reuse-delta. Useful only in the obscure case where
        wholesale enforcement of a different compression level on the
        packed data is desired.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--compression=&lt;n&gt;
</term>
<listitem>
<simpara>
        Specifies compression level for newly-compressed data in the
        generated pack.  If not specified,  pack compression level is
        determined first by pack.compression,  then by core.compression,
        and defaults to -1,  the zlib default,  if neither is set.
        Add --no-reuse-object if you want to force a uniform compression
        level on all data no matter the source.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--[no-]sparse
</term>
<listitem>
<simpara>
        Toggle the "sparse" algorithm to determine which objects to include in
        the pack, when combined with the "--revs" option. This algorithm
        only walks trees that appear in paths that introduce new objects.
        This can have significant performance benefits when computing
        a pack to send a small change. However, it is possible that extra
        objects are added to the pack-file if the included commits contain
        certain types of direct renames. If this option is not included,
        it defaults to the value of <emphasis>pack.useSparse</emphasis>, which is true unless
        otherwise specified.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--thin
</term>
<listitem>
<simpara>
        Create a "thin" pack by omitting the common objects between a
        sender and a receiver in order to reduce network transfer. This
        option only makes sense in conjunction with --stdout.
</simpara>
<simpara>Note: A thin pack violates the packed archive format by omitting
required objects and is thus unusable by Git without making it
self-contained. Use <emphasis>git index-pack --fix-thin</emphasis>
(see <xref linkend="git-index-pack(1)" />) to restore the self-contained property.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--shallow
</term>
<listitem>
<simpara>
        Optimize a pack that will be provided to a client with a shallow
        repository.  This option, combined with --thin, can result in a
        smaller pack at the cost of speed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--delta-base-offset
</term>
<listitem>
<simpara>
        A packed archive can express the base object of a delta as
        either a 20-byte object name or as an offset in the
        stream, but ancient versions of Git don't understand the
        latter.  By default, <emphasis>git pack-objects</emphasis> only uses the
        former format for better compatibility.  This option
        allows the command to use the latter format for
        compactness.  Depending on the average delta chain
        length, this option typically shrinks the resulting
        packfile by 3-5 per-cent.
</simpara>
<simpara>Note: Porcelain commands such as <emphasis>git gc</emphasis> (see <xref linkend="git-gc(1)" />),
<emphasis>git repack</emphasis> (see <xref linkend="git-repack(1)" />) pass this option by default
in modern Git when they put objects in your repository into pack files.
So does <emphasis>git bundle</emphasis> (see <xref linkend="git-bundle(1)" />) when it creates a bundle.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--threads=&lt;n&gt;
</term>
<listitem>
<simpara>
        Specifies the number of threads to spawn when searching for best
        delta matches.  This requires that pack-objects be compiled with
        pthreads otherwise this option is ignored with a warning.
        This is meant to reduce packing time on multiprocessor machines.
        The required amount of memory for the delta search window is
        however multiplied by the number of threads.
        Specifying 0 will cause Git to auto-detect the number of CPU's
        and set the number of threads accordingly.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--index-version=&lt;version&gt;[,&lt;offset&gt;]
</term>
<listitem>
<simpara>
        This is intended to be used by the test suite only. It allows
        to force the version for the generated pack index, and to force
        64-bit index entries on objects located above the given offset.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--keep-true-parents
</term>
<listitem>
<simpara>
        With this option, parents that are hidden by grafts are packed
        nevertheless.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--filter=&lt;filter-spec&gt;
</term>
<listitem>
<simpara>
        Omits certain objects (usually blobs) from the resulting
        packfile.  See <xref linkend="git-rev-list(1)" /> for valid
        <emphasis>&lt;filter-spec&gt;</emphasis> forms.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-filter
</term>
<listitem>
<simpara>
        Turns off any previous <emphasis>--filter=</emphasis> argument.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--missing=&lt;missing-action&gt;
</term>
<listitem>
<simpara>
        A debug option to help with future "partial clone" development.
        This option specifies how missing objects are handled.
</simpara>
<simpara>The form <emphasis>--missing=error</emphasis> requests that pack-objects stop with an error if
a missing object is encountered.  If the repository is a partial clone, an
attempt to fetch missing objects will be made before declaring them missing.
This is the default action.</simpara>
<simpara>The form <emphasis>--missing=allow-any</emphasis> will allow object traversal to continue
if a missing object is encountered.  No fetch of a missing object will occur.
Missing objects will silently be omitted from the results.</simpara>
<simpara>The form <emphasis>--missing=allow-promisor</emphasis> is like <emphasis>allow-any</emphasis>, but will only
allow object traversal to continue for EXPECTED promisor missing objects.
No fetch of a missing object will occur.  An unexpected missing object will
raise an error.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--exclude-promisor-objects
</term>
<listitem>
<simpara>
        Omit objects that are known to be in the promisor remote.  (This
        option has the purpose of operating only on locally created objects,
        so that when we repack, we still maintain a distinction between
        locally created objects [without .promisor] and objects from the
        promisor remote [with .promisor].)  This is used with partial clone.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--keep-unreachable
</term>
<listitem>
<simpara>
        Objects unreachable from the refs in packs named with
        --unpacked= option are added to the resulting pack, in
        addition to the reachable objects that are not in packs marked
        with *.keep files. This implies <emphasis>--revs</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--pack-loose-unreachable
</term>
<listitem>
<simpara>
        Pack unreachable loose objects (and their loose counterparts
        removed). This implies <emphasis>--revs</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unpack-unreachable
</term>
<listitem>
<simpara>
        Keep unreachable objects in loose form. This implies <emphasis>--revs</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--delta-islands
</term>
<listitem>
<simpara>
        Restrict delta matches based on "islands". See DELTA ISLANDS
        below.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-pack-objects(1)__delta_islands">
<title>DELTA ISLANDS</title>
<simpara>When possible, <emphasis>pack-objects</emphasis> tries to reuse existing on-disk deltas to
avoid having to search for new ones on the fly. This is an important
optimization for serving fetches, because it means the server can avoid
inflating most objects at all and just send the bytes directly from
disk. This optimization can't work when an object is stored as a delta
against a base which the receiver does not have (and which we are not
already sending). In that case the server "breaks" the delta and has to
find a new one, which has a high CPU cost. Therefore it's important for
performance that the set of objects in on-disk delta relationships match
what a client would fetch.</simpara>
<simpara>In a normal repository, this tends to work automatically. The objects
are mostly reachable from the branches and tags, and that's what clients
fetch. Any deltas we find on the server are likely to be between objects
the client has or will have.</simpara>
<simpara>But in some repository setups, you may have several related but separate
groups of ref tips, with clients tending to fetch those groups
independently. For example, imagine that you are hosting several "forks"
of a repository in a single shared object store, and letting clients
view them as separate repositories through <emphasis>GIT_NAMESPACE</emphasis> or separate
repos using the alternates mechanism. A naive repack may find that the
optimal delta for an object is against a base that is only found in
another fork. But when a client fetches, they will not have the base
object, and we'll have to find a new delta on the fly.</simpara>
<simpara>A similar situation may exist if you have many refs outside of
<emphasis>refs/heads/</emphasis> and <emphasis>refs/tags/</emphasis> that point to related objects (e.g.,
<emphasis>refs/pull</emphasis> or <emphasis>refs/changes</emphasis> used by some hosting providers). By
default, clients fetch only heads and tags, and deltas against objects
found only in those other groups cannot be sent as-is.</simpara>
<simpara>Delta islands solve this problem by allowing you to group your refs into
distinct "islands". Pack-objects computes which objects are reachable
from which islands, and refuses to make a delta from an object <emphasis>A</emphasis>
against a base which is not present in all of <emphasis>A</emphasis>'s islands. This
results in slightly larger packs (because we miss some delta
opportunities), but guarantees that a fetch of one island will not have
to recompute deltas on the fly due to crossing island boundaries.</simpara>
<simpara>When repacking with delta islands the delta window tends to get
clogged with candidates that are forbidden by the config. Repacking
with a big --window helps (and doesn't take as long as it otherwise
might because we can reject some object pairs based on islands before
doing any computation on the content).</simpara>
<simpara>Islands are configured via the <emphasis>pack.island</emphasis> option, which can be
specified multiple times. Each value is a left-anchored regular
expressions matching refnames. For example:</simpara>
<screen>[pack]
island = refs/heads/
island = refs/tags/</screen>
<simpara>puts heads and tags into an island (whose name is the empty string; see
below for more on naming). Any refs which do not match those regular
expressions (e.g., <emphasis>refs/pull/123</emphasis>) is not in any island. Any object
which is reachable only from <emphasis>refs/pull/</emphasis> (but not heads or tags) is
therefore not a candidate to be used as a base for <emphasis>refs/heads/</emphasis>.</simpara>
<simpara>Refs are grouped into islands based on their "names", and two regexes
that produce the same name are considered to be in the same
island. The names are computed from the regexes by concatenating any
capture groups from the regex, with a <emphasis>-</emphasis> dash in between. (And if
there are no capture groups, then the name is the empty string, as in
the above example.) This allows you to create arbitrary numbers of
islands. Only up to 14 such capture groups are supported though.</simpara>
<simpara>For example, imagine you store the refs for each fork in
<emphasis>refs/virtual/ID</emphasis>, where <emphasis>ID</emphasis> is a numeric identifier. You might then
configure:</simpara>
<screen>[pack]
island = refs/virtual/([0-9]+)/heads/
island = refs/virtual/([0-9]+)/tags/
island = refs/virtual/([0-9]+)/(pull)/</screen>
<simpara>That puts the heads and tags for each fork in their own island (named
"1234" or similar), and the pull refs for each go into their own
"1234-pull".</simpara>
<simpara>Note that we pick a single island for each regex to go into, using "last
one wins" ordering (which allows repo-specific config to take precedence
over user-wide config, and so forth).</simpara>
</simplesect>
<simplesect id="git-pack-objects(1)__configuration">
<title>CONFIGURATION</title>
<simpara>Various configuration variables affect packing, see
<xref linkend="git-config(1)" /> (search for "pack" and "delta").</simpara>
<simpara>Notably, delta compression is not used on objects larger than the
<emphasis>core.bigFileThreshold</emphasis> configuration variable and on files with the
attribute <emphasis>delta</emphasis> set to false.</simpara>
</simplesect>
<simplesect id="git-pack-objects(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-rev-list(1)" />
<xref linkend="git-repack(1)" />
<xref linkend="git-prune-packed(1)" /></simpara>
</simplesect>
<simplesect id="git-pack-objects(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
