{"thread":{"id":"64055","subject":"question: what does \"garbage\" field in \"git count-objects -v\" represent? Is it broken?","startedAt":"2025-08-28T16:32:23Z","lastAt":"2025-08-28T17:10:05Z","messageCount":4,"participants":["Daniele Sassoli","Elijah Newren","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"525120","messageId":"CADR1ei4LFVoLhMyya+wx8dXBmrRNSNy6L5Ye_MJgL4kzgtVR_A@mail.gmail.com","threadId":"64055","inReplyTo":null,"subject":"question: what does \"garbage\" field in \"git count-objects -v\" represent? Is it broken?","fromName":"Daniele Sassoli","fromEmail":"danielesassoli@gmail.com","sentAt":"2025-08-28T16:32:10Z","receivedAt":"2025-08-28T16:32:23Z","isPatch":false,"sender":{"key":"danielesassoli@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4007741?v=4"},"body":"Hi All,\n\nWhen reading the output `git count-objects -v` there is a `garbage` field. At\nfirst I thought this would highlight objects that are considered \"garbage\", i.e.\ncould be garbage collected. However, I kept noticing that this wasn't the case,\ndespite my repository having plenty of dangling objects (that where removed once\nI run `git gc --prune=now`), garbage kept being 0.\n\nI then turned to reading the docs, which state:\ngarbage: the number of files in the object database that are neither\nvalid loose objects nor valid packs\n\nI don't think I've ever seen a definition of an invalid object? I tried adding\nrandom chars to an object, effectively corrupting the repository(which `git\nfsck` correctly picked up), but count-objects kept returning 0 at the garbage\nfield.\n\nThe only way I've been able to get count-objects to report some garbage is by\ncreating files in the packs directory (or in any of the sub-directories of\n`objects` folder) with random names, like \"test\", or sometimes I've seen it\nreport the existence of lock files or even preserved files.\n\nSo my question is, am I fundamentally misunderstanding what garbage means, are\nthe docs simply unclear or is the functionality not working as expected?\n\nThanks for taking the time to read this and respond.\nDani\n"},{"id":"525122","messageId":"CABPp-BELxkVgXPJtQj1XACP5DSCiPsW36erQzMGSPwpsY-o-6Q@mail.gmail.com","threadId":"64055","inReplyTo":"CADR1ei4LFVoLhMyya+wx8dXBmrRNSNy6L5Ye_MJgL4kzgtVR_A@mail.gmail.com","subject":"Re: question: what does \"garbage\" field in \"git count-objects -v\" represent? Is it broken?","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2025-08-28T16:50:58Z","receivedAt":"2025-08-28T16:51:11Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, Aug 28, 2025 at 9:33 AM Daniele Sassoli\n<danielesassoli@gmail.com> wrote:\n>\n> Hi All,\n>\n> When reading the output `git count-objects -v` there is a `garbage` field. At\n> first I thought this would highlight objects that are considered \"garbage\", i.e.\n> could be garbage collected. However, I kept noticing that this wasn't the case,\n> despite my repository having plenty of dangling objects (that where removed once\n> I run `git gc --prune=now`), garbage kept being 0.\n>\n> I then turned to reading the docs, which state:\n> garbage: the number of files in the object database that are neither\n> valid loose objects nor valid packs\n>\n> I don't think I've ever seen a definition of an invalid object? I tried adding\n> random chars to an object, effectively corrupting the repository(which `git\n> fsck` correctly picked up), but count-objects kept returning 0 at the garbage\n> field.\n>\n> The only way I've been able to get count-objects to report some garbage is by\n> creating files in the packs directory (or in any of the sub-directories of\n> `objects` folder) with random names, like \"test\", or sometimes I've seen it\n> report the existence of lock files or even preserved files.\n>\n> So my question is, am I fundamentally misunderstanding what garbage means, are\n> the docs simply unclear or is the functionality not working as expected?\n>\n> Thanks for taking the time to read this and respond.\n> Dani\n\nThe most common way I've seen to get garbage files into the repository\nis either someone pushing from elsewhere into the current repository\nand interrupting the transfer mid-way through, or someone fetching\nfrom elsewhere into the current repository and interrupting the\ntransfer mid-way through.  In either case, there will be a partial\npackfile with a temporary name (since we use a temporary name at the\nbeginning and rename to the final location after the transfer is\ncomplete), and `git count-objects -v` will report it as garbage.\n"},{"id":"525124","messageId":"xmqqy0r3v0jz.fsf@gitster.g","threadId":"64055","inReplyTo":"CADR1ei4LFVoLhMyya+wx8dXBmrRNSNy6L5Ye_MJgL4kzgtVR_A@mail.gmail.com","subject":"Re: question: what does \"garbage\" field in \"git count-objects -v\" represent? Is it broken?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-28T17:05:52Z","receivedAt":"2025-08-28T17:05:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniele Sassoli <danielesassoli@gmail.com> writes:\n\n> When reading the output `git count-objects -v` there is a `garbage` field. At\n> first I thought this would highlight objects that are considered \"garbage\", i.e.\n> could be garbage collected. However, I kept noticing that this wasn't the case,\n> despite my repository having plenty of dangling objects (that where removed once\n> I run `git gc --prune=now`), garbage kept being 0.\n\ncount-objects is about quick housekeeping stats and does not (and\nshould never) analyze reachability like fsck does, which is required\nto tell which objects are dangling.\n\n> I then turned to reading the docs, which state:\n> garbage: the number of files in the object database that are neither\n> valid loose objects nor valid packs\n>\n> I don't think I've ever seen a definition of an invalid object?\n> I tried adding random chars to an object, effectively corrupting\n> the repository(which `git fsck` correctly picked up), but\n> count-objects kept returning 0 at the garbage field.\n\ncount-objects is about quick housekeeping stats and does not (and\nshould never) analyze object contents like fsck does, which is\nrequired to tell which objects are corrupt.\n\n> The only way I've been able to get count-objects to report some garbage is by\n> creating files in the packs directory (or in any of the sub-directories of\n> `objects` folder) with random names, like \"test\", or sometimes I've seen it\n> report the existence of lock files or even preserved files.\n>\n> So my question is, am I fundamentally misunderstanding what garbage means, are\n> the docs simply unclear or is the functionality not working as expected?\n>\n> Thanks for taking the time to read this and respond.\n> Dani\n\nYou are fundamentally understanding correctly.  The command tells\nyou it found a garbage when you do this:\n\n    $ mkdir -p .git/objects/00 && >.git/objects/00/tmp-garbage\n    $ git count-objects -v\n    warning: garbage found: .git/objects/00/tmp-garbage\n\n"},{"id":"525125","messageId":"CADR1ei41b6oNONF1GPiWMm+LdwbV7_2K=vBy1b30OrqpyfMbvQ@mail.gmail.com","threadId":"64055","inReplyTo":"xmqqy0r3v0jz.fsf@gitster.g","subject":"Re: question: what does \"garbage\" field in \"git count-objects -v\" represent? Is it broken?","fromName":"Daniele Sassoli","fromEmail":"danielesassoli@gmail.com","sentAt":"2025-08-28T17:09:53Z","receivedAt":"2025-08-28T17:10:05Z","isPatch":false,"sender":{"key":"danielesassoli@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4007741?v=4"},"body":"On Thu, 28 Aug 2025 at 19:05, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Daniele Sassoli <danielesassoli@gmail.com> writes:\n>\n> > When reading the output `git count-objects -v` there is a `garbage` field. At\n> > first I thought this would highlight objects that are considered \"garbage\", i.e.\n> > could be garbage collected. However, I kept noticing that this wasn't the case,\n> > despite my repository having plenty of dangling objects (that where removed once\n> > I run `git gc --prune=now`), garbage kept being 0.\n>\n> count-objects is about quick housekeeping stats and does not (and\n> should never) analyze reachability like fsck does, which is required\n> to tell which objects are dangling.\n\nTotally agree with this.\n\n>\n> > I then turned to reading the docs, which state:\n> > garbage: the number of files in the object database that are neither\n> > valid loose objects nor valid packs\n> >\n> > I don't think I've ever seen a definition of an invalid object?\n> > I tried adding random chars to an object, effectively corrupting\n> > the repository(which `git fsck` correctly picked up), but\n> > count-objects kept returning 0 at the garbage field.\n>\n> count-objects is about quick housekeeping stats and does not (and\n> should never) analyze object contents like fsck does, which is\n> required to tell which objects are corrupt.\n>\n> > The only way I've been able to get count-objects to report some garbage is by\n> > creating files in the packs directory (or in any of the sub-directories of\n> > `objects` folder) with random names, like \"test\", or sometimes I've seen it\n> > report the existence of lock files or even preserved files.\n> >\n> > So my question is, am I fundamentally misunderstanding what garbage means, are\n> > the docs simply unclear or is the functionality not working as expected?\n> >\n> > Thanks for taking the time to read this and respond.\n> > Dani\n>\n> You are fundamentally understanding correctly.  The command tells\n> you it found a garbage when you do this:\n>\n>     $ mkdir -p .git/objects/00 && >.git/objects/00/tmp-garbage\n>     $ git count-objects -v\n>     warning: garbage found: .git/objects/00/tmp-garbage\n>\nDo you both agree that the term garbage is somewhat misleading? I've spoken\nabout this both on Discord[1] and in person at the recent Git Mini Summit, and\nboth times people expected to see garbage-collectable objects being reported by\nthis field (which, as Junio says, wouldn't be correct, but that's what people\nthink of).\nOther users also seem to be confused by this as shown by [2].\n\nAt the very least, I believe the documentation could do with some clarification\nand maybe we should even look at changing the wording of the field.\nI wanted to triple check my understand was correct before submitting a patch.\n\nThanks for your feedback.\n\n[1]https://discord.com/channels/1042895022950994071/1156706741875130499/1408738703156973640\n[2]https://stackoverflow.com/questions/30999879/git-garbage-size-out-of-control-need-understanding\n"}]}