From what I understood any object gets garbage collected when they have no refs.
What is the best way to prevent collection of objects that we want to persist in the database?
A use case is when in a pull request one makes changes (maybe according to a code review) and previous commits become detached, they are not going to be merged in the repository but they should always be available in order to allow tracing of the changes in the pull request.
Now CommitA2 is what will be in the change history, but the pull-request will still have a link pointing to the old CommitA. In some years we want to be able to see what the pull-request was about and what its comments were referring to.
How does one prevent the commit from being collected by GC?
Give it a tag is the first solution that comes to my mind.
Refs don't have to be branches or tags, you can keep local refs to anything you want.
Here's a simple "make me another snapshot ref for pull 137",
next=$((`git rev-list --no-walk --count --glob=refs/snap/pull/137/head-v*`+1))
git update-ref refs/snap/pull/137/head-v$next refs/pull/137/head
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With