Overview
Git uses pack files to efficiently store objects. Instead of storing each object as a separate file, Git can bundle many objects into a single “pack” file using delta compression.Pack files dramatically reduce repository size by storing only differences between similar objects.
Why Pack Files?
Initially, Git stores each object as a separate file in.git/objects/. This is simple but inefficient:
- Space: Duplicate or similar content is stored multiple times
- Network: Fetching requires transferring many small files
- Performance: Managing thousands of files is slower than one large file
- Delta compression: Store differences instead of full content
- Bundling: Combine many objects into one file
- Indexing: Fast lookup with accompanying index files
Pack File Structure
Pack File Format
Index File Format
Each pack file has a corresponding.idx index file for fast lookup:
Object Types in Pack Files
Pack files can contain different object representations:1. Undeltified Objects
Full object content:2. Deltified Objects
Stored as differences from a base object:Delta Compression
Git uses the xdelta algorithm to compute deltas:Creating Pack Files
Manual Packing
Pack Options
--depth=<n>
--depth=<n>
Maximum delta depth (default: 50). Deeper deltas save more space but are slower to access.
--window=<n>
--window=<n>
Number of objects to consider for delta compression (default: 10).
-a, --all
-a, --all
Pack all objects, not just loose ones.
-d, --delete-redundant
-d, --delete-redundant
Remove redundant packs after repacking.
Inspecting Pack Files
View Pack Contents
Understanding verify-pack Output
SHA-1 type size packed-size offset [depth base]
Pack File Strategies
Pack Generation Strategy
Git considers several factors when creating deltas:- File similarity: Similar content is likely to delta well
- Recency: Newer objects are likely to be accessed more
- Type grouping: Objects of the same type often compress better
Delta Base Selection
Performance Considerations
Optimization Tips
Multi-Pack Index
For repositories with many pack files:Network Packs
During fetch/push, Git creates custom packs:Thin packs can reference objects not in the pack itself, assuming they exist in the destination repository.
Related Topics
- Object Model - Understanding Git objects
- Transfer Protocols - How packs are transferred
- Commit Graph - Optimizing commit access
