wire / wire-format / git-packfile

Git packfile format

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.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: Git packfile format

wire 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.

fieldsizemeaning
Magic4 bytes'PACK' (0x50 0x41 0x43 0x4B).
Version4 bytesPack version: 2 (default) or 3 (experimental).
Number of objects4 bytesCount of objects in this pack (big-endian).
Object entry (type+size)variableFirst 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 datavariablezlib-deflated object content (or delta instructions for OFS/REF_DELTA).
OFS_DELTA base offsetvariableFor type 6: negative offset from this entry to the base object (variable-length, MSB continuation with offset encoding).
REF_DELTA base SHA-120 bytesFor type 7: SHA-1 of the base object (must be in this or another pack).
Pack checksum20 bytesSHA-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


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/git-packfile or /wire-format/git-packfile.json