wire / wire-format / git-packfile
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.
aka: Git packfile format
spec: Git documentation (pack-format.txt)
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.
| field | size | meaning |
|---|---|---|
| Magic | 4 bytes | 'PACK' (0x50 0x41 0x43 0x4B). |
| Version | 4 bytes | Pack version: 2 (default) or 3 (experimental). |
| Number of objects | 4 bytes | Count of objects in this pack (big-endian). |
| Object entry (type+size) | variable | 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). |
| Object data | variable | zlib-deflated object content (or delta instructions for OFS/REF_DELTA). |
| OFS_DELTA base offset | variable | For type 6: negative offset from this entry to the base object (variable-length, MSB continuation with offset encoding). |
| REF_DELTA base SHA-1 | 20 bytes | For type 7: SHA-1 of the base object (must be in this or another pack). |
| Pack checksum | 20 bytes | SHA-1 of all preceding bytes in the pack. |
example:
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
Pack header 'PACK' version 2, 1 object, then a blob entry
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/git-packfile
or /wire-format/git-packfile.json