Git prune-packed: Remove Loose Copies of Packed Objects
Learn how git prune-packed removes redundant loose object files when the same objects already exist in pack files.
Advanced
What problem does `git prune-packed` solve?
Git can store an object as a loose object file and also have that same object inside a pack file. Once the packed copy exists, the loose copy is redundant. `git prune-packed` finds those duplicate loose copies and removes them. It does not decide whether an object is reachable from a ref.
Quick check
What makes a loose object eligible for `git prune-packed`?
Inspect before changing anything
The safest first step is the dry run. It reports loose object files that would be removed without deleting them.
git prune-packed --dry-runQuick check
What does `--dry-run` change?
Remove the redundant loose objects
git prune-packedThe command searches the configured object directory for objects that occur both as loose objects and in pack files, then removes those redundant loose files. The packed copies remain.
Quiet mode
git prune-packed --quiet`--quiet` suppresses the progress indicator. It does not change which objects qualify for removal.
Quick check
Which command removes redundant loose copies while retaining the packed copies?
Do not confuse it with `git prune`
`git prune` is about reachability: it can remove eligible unreachable objects. `git prune-packed` is about representation: it removes loose files when the same objects already exist in a pack. An object can be reachable and still have a redundant loose copy, so reachability and packedness are different questions.
Quick check
Can `git prune-packed` remove the loose copy of a reachable object?
How it fits with other storage commands
`git pack-objects` constructs a pack. `git index-pack` builds an index for an existing pack. `git repack` performs repository-level repacking and can invoke `git prune-packed` to remove redundant loose objects. `git prune` handles unreachable-object cleanup. `git prune-packed` sits specifically at the boundary where an object is already safely represented inside a pack.
git pack-objects --help
git repack --help
git prune --help
git prune-packed --helpPractice 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.