{
  "id": "wire-format/git-packfile",
  "family": "wire-format",
  "slug": "git-packfile",
  "title": "Git packfile format",
  "summary": "A Git packfile (.pack) stores objects (commits, trees, blobs, tags) in a compressed, delta-encoded form. Header: 4-byte magic 'PACK', 4-byte version (2), 4-byte number of objects. Then object entries: type+size (variable-length), compressed object (zlib), with deltas (OFS_DELTA type 6, REF_DELTA type 7) referencing a base. Trailer: 20-byte SHA-1 checksum of the pack.",
  "kind": "wire-format",
  "aliases": [
    "Git packfile format"
  ],
  "status": "standard",
  "verification": "verified",
  "tier": "B",
  "source_url": "https://www.rfc-editor.org/",
  "source_version": "retrieved 2026-05-29",
  "retrieved_date": "2026-05-29",
  "ext_type": "wire-format@1",
  "ext": {
    "spec": "Git documentation (pack-format.txt)",
    "summary": "A Git packfile (.pack) stores objects (commits, trees, blobs, tags) in a compressed, delta-encoded form. Header: 4-byte magic 'PACK', 4-byte version (2), 4-byte number of objects. Then object entries: type+size (variable-length), compressed object (zlib), with deltas (OFS_DELTA type 6, REF_DELTA type 7) referencing a base. Trailer: 20-byte SHA-1 checksum of the pack.",
    "structure": [
      {
        "field": "Magic",
        "size": "4 bytes",
        "meaning": "'PACK' (0x50 0x41 0x43 0x4B)."
      },
      {
        "field": "Version",
        "size": "4 bytes",
        "meaning": "Pack version: 2 (default) or 3 (experimental)."
      },
      {
        "field": "Number of objects",
        "size": "4 bytes",
        "meaning": "Count of objects in this pack (big-endian)."
      },
      {
        "field": "Object entry (type+size)",
        "size": "variable",
        "meaning": "First byte: 3-bit type (1 commit, 2 tree, 3 blob, 4 tag, 6 OFS_DELTA, 7 REF_DELTA) + 4-bit size (MSB continuation). Followed by more bytes if size needs more bits (7 bits per continuation byte, MSB = continue)."
      },
      {
        "field": "Object data",
        "size": "variable",
        "meaning": "zlib-deflated object content (or delta instructions for OFS/REF_DELTA)."
      },
      {
        "field": "OFS_DELTA base offset",
        "size": "variable",
        "meaning": "For type 6: negative offset from this entry to the base object (variable-length, MSB continuation with offset encoding)."
      },
      {
        "field": "REF_DELTA base SHA-1",
        "size": "20 bytes",
        "meaning": "For type 7: SHA-1 of the base object (must be in this or another pack)."
      },
      {
        "field": "Pack checksum",
        "size": "20 bytes",
        "meaning": "SHA-1 of all preceding bytes in the pack."
      }
    ],
    "example_hex": "50 41 43 4b 00 00 00 02 00 00 00 01 03 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
    "example_decoded": "Pack header 'PACK' version 2, 1 object, then a blob entry",
    "notes": [
      "Packfiles are generated by 'git repack' and 'git gc'; loose objects are individual zlib-compressed files in .git/objects/.",
      "Delta chains: OFS_DELTA references by offset (preferred, faster), REF_DELTA by SHA-1 (for cross-pack).",
      "Thin packs (used in push/fetch) can reference objects not in the pack (base is in the receiver's repo).",
      "Index file (.idx) maps object SHA-1 -> offset in the pack for O(1) lookup.",
      "Pack v3 adds .keep and bitmap indexes for faster reachability."
    ]
  },
  "updated": "2026-05-29"
}
