git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: question: what does "garbage" field in "git count-objects -v" represent? Is it broken?

From
Elijah Newren <newren@gmail.com>
Date
Aug 28, 2025, 16:50 UTC
Message-ID
<CABPp-BELxkVgXPJtQj1XACP5DSCiPsW36erQzMGSPwpsY-o-6Q@mail.gmail.com>
In-Reply-To
<CADR1ei4LFVoLhMyya+wx8dXBmrRNSNy6L5Ye_MJgL4kzgtVR_A@mail.gmail.com>

On Thu, Aug 28, 2025 at 9:33 AM Daniele Sassoli <danielesassoli@gmail.com> wrote:

Show 28 quoted lines
>
> Hi All,
>
> When reading the output `git count-objects -v` there is a `garbage` field. At
> first I thought this would highlight objects that are considered "garbage", i.e.
> could be garbage collected. However, I kept noticing that this wasn't the case,
> despite my repository having plenty of dangling objects (that where removed once
> I run `git gc --prune=now`), garbage kept being 0.
>
> I then turned to reading the docs, which state:
> garbage: the number of files in the object database that are neither
> valid loose objects nor valid packs
>
> I don't think I've ever seen a definition of an invalid object? I tried adding
> random chars to an object, effectively corrupting the repository(which `git
> fsck` correctly picked up), but count-objects kept returning 0 at the garbage
> field.
>
> The only way I've been able to get count-objects to report some garbage is by
> creating files in the packs directory (or in any of the sub-directories of
> `objects` folder) with random names, like "test", or sometimes I've seen it
> report the existence of lock files or even preserved files.
>
> So my question is, am I fundamentally misunderstanding what garbage means, are
> the docs simply unclear or is the functionality not working as expected?
>
> Thanks for taking the time to read this and respond.
> Dani

The most common way I've seen to get garbage files into the repository is either someone pushing from elsewhere into the current repository and interrupting the transfer mid-way through, or someone fetching from elsewhere into the current repository and interrupting the transfer mid-way through. In either case, there will be a partial packfile with a temporary name (since we use a temporary name at the beginning and rename to the final location after the transfer is complete), and `git count-objects -v` will report it as garbage.

Previous: Daniele SassoliNext: Junio C Hamano
Message 2 of 4 in “question: what does "garbage" field in "git count-objects -v" represent? Is it broken?”
  1. Daniele SassoliAug 28, 2025
  2. Elijah NewrenAug 28, 2025
  3. Junio C HamanoAug 28, 2025
  4. Daniele SassoliAug 28, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.