Skip to content

format-pack Git Command Guide

The git format-pack format stores Git objects in compressed delta-encoded archives to optimize storage space, network transfer, and repository performance. Pack files are the primary storage mechanism for Git repositories.

FieldSizeDescription
Signature4 bytes’P’, ‘A’, ‘C’, ‘K’
Version4 bytesVersion 2 or 3 (network byte order)
Object Count4 bytesNumber of objects in pack (network byte order)

Undeltified Objects:

  • type and length (3-bit type, (n-1)*7+4-bit length)
  • compressed object data

Delta Objects:

  • type and length (3-bit type, (n-1)*7+4-bit length)
  • base object name (SHA-1 for OBJ_REF_DELTA)
  • compressed delta data
Type ValueNameBase Reference
6 (0b110)OBJ_REF_DELTASHA-1 hash of base object
7 (0b111)OBJ_OFS_DELTANegative offset to base object in pack
Type ValueNameDescription
1OBJ_COMMITCommit object
2OBJ_TREETree object
3OBJ_BLOBBlob (file content) object
4OBJ_TAGTag object
Terminal window
ls -la .git/objects/pack/

List all pack files in the repository.

Terminal window
git verify-pack .git/objects/pack/pack-*.idx

Check pack file integrity and show object statistics.

Terminal window
git pack-objects custom-pack < object-list.txt

Create a custom pack file from specified objects.

Terminal window
git repack -a -d

Repack all objects into a single pack, removing old packs.

Terminal window
find .git/objects/pack -name "*.pack" -exec git unpack-objects {} +

Unpack objects from pack files to loose objects.

Terminal window
git for-each-ref --format='%(objectname)' | git pack-objects verify-pack

Verify packs contain expected objects.

Terminal window
git pack-objects --thin thin-pack < object-list.txt

Create thin pack that references objects not in the pack.

How does Git decide when to create pack files?

Section titled “How does Git decide when to create pack files?”

Git creates pack files during git gc, git repack, or when the number of loose objects exceeds gc.autoPackLimit (default 50).

All Git objects (commits, trees, blobs, tags) can be packed using delta compression to save space.

What’s the difference between thin and normal packs?

Section titled “What’s the difference between thin and normal packs?”

Thin packs reference base objects not included in the pack, allowing smaller transfers at the cost of requiring access to referenced objects.

Use git verify-pack -v .git/objects/pack/pack-*.idx to see all objects, their sizes, and delta chains.

How do I recover from a corrupted pack file?

Section titled “How do I recover from a corrupted pack file?”

For corrupted packs, try git fsck --full first. If recovery fails, use backups or attempt unpacking with git unpack-objects < packfile.

Compression depends on similarity between objects, Git version pack compression algorithm settings, and whether deltas are enabled.

Recent objects stay loose for performance. Only gc/periodic maintenance consolidates them into packs.

  1. Storage Efficiency: Compresses thousands of objects into single files with delta compression
  2. Memory Mapping: Allows efficient memory mapping of object data during operations
  3. Network Efficiency: Enables fast push/pull operations with thin pack optimization
  4. Clone Performance: Speeds up initial cloning by bundling repository data
  5. Backup Strategy: Facilitates repository backups and archival
  6. Scalability: Supports repositories with millions of objects through multi-pack-index