threads / discuss / 55133

GC can lose objects pointed to only by notes?

Subject: GC can lose objects pointed to only by notes?

## tl;dr

2 messages between Feb 10, 2021 and Feb 10, 2021.

replies: 1people: 2as markdown or json

Martin von Zweigbergk· Feb 10, 2021, 19:51 UTC · lore

From the "NOTES" section in `git help gc`: "[...] it will keep [..] objects referenced by the index, remote-tracking branches, notes saved by git notes under refs/notes/"

I had interpreted that as saying that it will keep objects pointed to by notes saved under refs/notes. I had a repo with lots of commits referred to only by notes. When I ran `git gc`, the commits they pointed to were deleted (I had a backup, so no big deal). I now understand that the documentation actually meant that "objects referenced by the index and remote-tracking branches, as well as notes saved by git notes under refs/notes/" are kept.

It seems that the documentation should at least be clarified. I had read the documentation before I decided to rely on notes for keeping my commits alive (which I now know was a mistake). I'll make sure to add refs pointing directly to my commits instead now. I can send a patch for the documentation unless someone else beats me to it (it's been a while since my last patch for git, so it'll take some time for me to get set up).

For a while, I also thought that `git gc` should be updated to also keep objects with notes attached. However, as far as I understand, the notes refs are never rewritten/rewound (only fast-forwarded), which means that you would never be able to get rid of the old commits in that case (just like you're already not able to get rid of old notes). So I understand that you probably don't want to make that change.

Junio C Hamano· Feb 10, 2021, 20:20 UTC · re: Martin von Zweigbergk · lore

Re: GC can lose objects pointed to only by notes?

Martin von Zweigbergk <martinvonz@gmail.com> writes:
Show 6 quoted lines
> From the "NOTES" section in `git help gc`:
> "[...] it will keep [..] objects referenced by the index,
> remote-tracking branches, notes saved by git notes under refs/notes/"
>
> I had interpreted that as saying that it will keep objects pointed to
> by notes saved under refs/notes.
The documentation needs updating.

There is no reachability from the notes that point at an otherwise uninteresting objects that are not pointed at by real refs, so a note that talks about a commit that is pruned will become stale.

It is the reason why we need the "git notes prune" subcommand.
Thanks.

← back to recent threads