Git Reference ยท Inspecting History
git count-objects command
Reference for git count-objects: count loose objects, packs and garbage in a repository, read the -v and -H output, and decide when to run git gc.
git count-objects reports how many loose objects a repository has and how much disk they take. A loose object is a single zlib-compressed file under .git/objects/xx/; new commits, trees and blobs start out that way. Periodically Git packs them into compact packfiles, so a growing loose count means a git gc is due.
With -v it also reports packed objects, the number and size of packs, objects that could be pruned, and stray files ("garbage") that Git does not recognize.
git count-objects [-v | --verbose] [-H | --human-readable]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
Plain output is one line: N objects, S kilobytes for the loose objects. The size is disk space used (blocks), not content size, so it differs between file systems.
With -v, each line is a key: value pair:
| Key | Meaning |
|---|---|
count |
Number of loose objects. |
size |
Disk space used by loose objects, in KiB. |
in-pack |
Number of objects stored in packfiles. |
packs |
Number of packfiles. |
size-pack |
Disk space used by packs, in KiB. |
prune-packable |
Loose objects that also exist in a pack; git prune-packed would remove them. |
garbage |
Number of files in the object store that are not recognized. |
size-garbage |
Disk space used by that garbage, in KiB. |
alternate: <path> |
One line per alternate object store in use. |
-H (--human-readable) prints sizes as 12.00 KiB or 3.40 MiB; it implies -v.
Usage notes
- Identical content is stored once, so adding a second file with the same bytes does not add an object, as the second example shows.
git gc --autoruns when loose objects exceedgc.auto(default 6700) or packs exceedgc.autoPackLimit(default 50). The check estimates the loose count by looking at a single fan-out directory, so it is approximate.- Garbage typically comes from interrupted operations such as a killed
git repack; the file names are shown with the warning.git gcorgit pruneclears recoverable cases. - The counts cover the repository's own object store. Objects reachable through alternates (shared clones) are not included, only listed.
- After
git gc,countis usually 0 and the remaining unreachable loose objects wait untilgc.pruneExpire(two weeks) has passed. - For a breakdown of space per object, use
git cat-file --batch-all-objects --batch-checkorgit rev-list --objects.