Git Object Storage: Count, Repack, and Verify Packfiles
Inspect loose objects and packfiles with git count-objects, reorganize storage with git repack in a disposable repository, and verify a pack with git verify-pack.
Advanced
The two storage forms: loose objects and packs
Git can store individual objects as loose files under the object database, or store many objects together in packfiles. `git count-objects` lets you inspect how much data is loose and how much is already packed. This is storage accounting, not a history inspection command.
git count-objects
git count-objects -v
git count-objects -v -HQuick check
After `git count-objects -v`, which field reports the number of objects currently stored in packfiles?
Read the detailed storage report
The verbose report separates loose-object counts and sizes from packed-object counts and sizes. `prune-packable` identifies loose objects that are also present in packs; `garbage` counts files in the object database that are neither valid loose objects nor valid packs. `-H` changes byte-size reporting to human-readable units.
git count-objects -v
git count-objects -v -HQuick check
What does a nonzero `garbage` value mean?
Pack loose objects with git repack
`git repack` combines objects that are not currently in a pack into pack storage and can reorganize existing packs. For a controlled learning experiment, `-a` asks Git to pack all referenced objects and `-d` asks it to remove redundant old packs after the new pack is created. Because this changes repository storage, perform the operation in a disposable repository when learning it.
git repack -ad
git count-objects -vQuick check
What storage change should you expect after `git repack -ad` in a small disposable repository?
Inspect a specific pack with git verify-pack
`git verify-pack` operates on a pack index file ending in `.idx`. It verifies the index and its corresponding pack file. The normal form checks the pack; `-s` reports only delta-chain statistics without verifying pack contents, while `-v` verifies the pack and additionally lists its objects and delta-chain information.
git verify-pack .git/objects/pack/pack-<id>.idx
git verify-pack -s .git/objects/pack/pack-<id>.idx
git verify-pack -v .git/objects/pack/pack-<id>.idxQuick check
Which input does `git verify-pack` expect?
Connect count, repack, and verification
A useful storage-inspection workflow is: measure first, create or inspect pack storage in a disposable repository, measure again, then verify the resulting index. This lets you distinguish storage layout from repository integrity: `count-objects` reports storage quantities, `repack` changes layout, and `verify-pack` validates a selected packed archive.
git count-objects -v -H
git repack -ad
git count-objects -v -H
ls .git/objects/pack/*.idx
git verify-pack -v .git/objects/pack/pack-<id>.idxQuick check
Which command is the integrity-oriented check rather than a storage-layout report?
What this lesson does not own
`git fsck` owns repository object connectivity and validity. `git gc`, `git maintenance`, `git prune`, and `git prune-packed` are maintenance/cleanup surfaces and are not interchangeable with storage inspection. Multi-pack indexes and commit-graph files are separate storage subsystems and will not be smuggled into this lesson as incidental flags.
Practice what you learned
Use the dedicated Git code-completion exercise for this lesson.
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.