{"thread":{"id":"50695","subject":"how can i \"gc\" or \"prune\" objects related to a deleted remote?","startedAt":"2019-03-08T15:36:50Z","lastAt":"2019-03-20T05:22:30Z","messageCount":4,"participants":["Robert P. J. Day","Jeff King","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"370989","messageId":"alpine.LFD.2.21.1903081029510.25426@localhost.localdomain","threadId":"50695","inReplyTo":null,"subject":"how can i \"gc\" or \"prune\" objects related to a deleted remote?","fromName":"Robert P. J. Day","fromEmail":"rpjday@crashcourse.ca","sentAt":"2019-03-08T15:36:44Z","receivedAt":"2019-03-08T15:36:50Z","isPatch":false,"sender":{"key":"rpjday@crashcourse.ca","avatar":"https://avatars.githubusercontent.com/u/226084077?v=4"},"body":"\n  writing a short tutorial on how to add a remote and work with it\nand, as a final step, show how, if one is uninterested in the remote\nafter all, one can simply delete it, but i also want to show how one\ncan then prune or garbage collect the objects related to that remote,\nbut i can't figure out how.\n\n  as an example, i cloned the linux kernel source tree, then added\nthe linux-next repo as a remote -- the end result was two pack files\n(the smaller one i'm assuming being for linux-next):\n\n$ ls -l .git/objects/pack\ntotal 2723632\n-r--r--r--. 1 rpjday rpjday    1215376 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.idx\n-r--r--r--. 1 rpjday rpjday   38402840 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.pack\n-r--r--r--. 1 rpjday rpjday  204032716 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.idx\n-r--r--r--. 1 rpjday rpjday 2545333327 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.pac\n$\n\n  after playing with a couple branches from the new remote, i deleted\nthe remote, then also did things like clear the reflog, delete any\nlocal tracking branches related to the deleted remote, and so on, but\ni can't seem to prune the objects that should no longer be reachable\nnow that i deleted that remote.\n\n  what am i overlooking? is it because those objects are in a separate\npack file? do i need to repack first? what is hanging onto those\nobjects in that second pack file such that they can't be garbage\ncollected?\n\nrday\n\n-- \n\n========================================================================\nRobert P. J. Day                                 Ottawa, Ontario, CANADA\n                  http://crashcourse.ca/dokuwiki\n\nTwitter:                                       http://twitter.com/rpjday\nLinkedIn:                               http://ca.linkedin.com/in/rpjday\n========================================================================\n"},{"id":"371881","messageId":"20190319063904.GC31801@sigill.intra.peff.net","threadId":"50695","inReplyTo":"alpine.LFD.2.21.1903081029510.25426@localhost.localdomain","subject":"Re: how can i \"gc\" or \"prune\" objects related to a deleted remote?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-03-19T06:39:05Z","receivedAt":"2019-03-19T06:39:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 08, 2019 at 10:36:44AM -0500, Robert P. J. Day wrote:\n\n>   as an example, i cloned the linux kernel source tree, then added\n> the linux-next repo as a remote -- the end result was two pack files\n> (the smaller one i'm assuming being for linux-next):\n> \n> $ ls -l .git/objects/pack\n> total 2723632\n> -r--r--r--. 1 rpjday rpjday    1215376 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.idx\n> -r--r--r--. 1 rpjday rpjday   38402840 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.pack\n> -r--r--r--. 1 rpjday rpjday  204032716 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.idx\n> -r--r--r--. 1 rpjday rpjday 2545333327 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.pac\n> $\n> \n>   after playing with a couple branches from the new remote, i deleted\n> the remote, then also did things like clear the reflog, delete any\n> local tracking branches related to the deleted remote, and so on, but\n> i can't seem to prune the objects that should no longer be reachable\n> now that i deleted that remote.\n\nAfter arriving at a similar state, I did:\n\n  git remote rm linux-next\n  git tag -d next-20190319\n  git gc --prune=now\n\nMy guess is you forgot the tag? There's not a general solution there,\nbecause the tags all get intermingled. Git has no idea which ones came\nfrom which remote. However, if you have the commit id of an object you\nexpect to be going away, you can use:\n\n  git for-each-ref --contains=$that_commit\n\nto see what's still pointing to it (even indirectly).\n\nExpiring the HEAD reflog is another frequently-forgotten thing, but in\nmy case I had never actually checked out any branches. You should be\nable to do \"git reflog expire --expire-unreachable=now --all\" for that.\n\n>   what am i overlooking? is it because those objects are in a separate\n> pack file? do i need to repack first? what is hanging onto those\n> objects in that second pack file such that they can't be garbage\n> collected?\n\nThe two packs shouldn't matter. The gc process works by repacking what's\nreachable, not including what's not, and then deleting the old packs.\n\n-Peff\n"},{"id":"371896","messageId":"878sxbdx51.fsf@evledraar.gmail.com","threadId":"50695","inReplyTo":"20190319063904.GC31801@sigill.intra.peff.net","subject":"Re: how can i \"gc\" or \"prune\" objects related to a deleted remote?","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-03-19T09:35:54Z","receivedAt":"2019-03-19T09:36:00Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Tue, Mar 19 2019, Jeff King wrote:\n\n> On Fri, Mar 08, 2019 at 10:36:44AM -0500, Robert P. J. Day wrote:\n>\n>>   as an example, i cloned the linux kernel source tree, then added\n>> the linux-next repo as a remote -- the end result was two pack files\n>> (the smaller one i'm assuming being for linux-next):\n>>\n>> $ ls -l .git/objects/pack\n>> total 2723632\n>> -r--r--r--. 1 rpjday rpjday    1215376 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.idx\n>> -r--r--r--. 1 rpjday rpjday   38402840 Mar  8 09:44 pack-08cc266c0914e924961a1c8412fdf8746d327d7e.pack\n>> -r--r--r--. 1 rpjday rpjday  204032716 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.idx\n>> -r--r--r--. 1 rpjday rpjday 2545333327 Mar  8 09:42 pack-1036510bb74967c91093fc0cd8982683a66dbf5f.pac\n>> $\n>>\n>>   after playing with a couple branches from the new remote, i deleted\n>> the remote, then also did things like clear the reflog, delete any\n>> local tracking branches related to the deleted remote, and so on, but\n>> i can't seem to prune the objects that should no longer be reachable\n>> now that i deleted that remote.\n>\n> After arriving at a similar state, I did:\n>\n>   git remote rm linux-next\n>   git tag -d next-20190319\n>   git gc --prune=now\n>\n> My guess is you forgot the tag? There's not a general solution there,\n> because the tags all get intermingled. Git has no idea which ones came\n> from which remote. However, if you have the commit id of an object you\n> expect to be going away, you can use:\n>\n>   git for-each-ref --contains=$that_commit\n\nNot a general solution, but if you know you have one remote left, and\nyou don't have unpushed locally created tags, you can do a:\n\n    git fetch origin --prune --prune-tags\n\n> to see what's still pointing to it (even indirectly).\n>\n> Expiring the HEAD reflog is another frequently-forgotten thing, but in\n> my case I had never actually checked out any branches. You should be\n> able to do \"git reflog expire --expire-unreachable=now --all\" for that.\n>\n>>   what am i overlooking? is it because those objects are in a separate\n>> pack file? do i need to repack first? what is hanging onto those\n>> objects in that second pack file such that they can't be garbage\n>> collected?\n>\n> The two packs shouldn't matter. The gc process works by repacking what's\n> reachable, not including what's not, and then deleting the old packs.\n>\n> -Peff\n"},{"id":"371954","messageId":"20190320052226.GA9650@sigill.intra.peff.net","threadId":"50695","inReplyTo":"878sxbdx51.fsf@evledraar.gmail.com","subject":"Re: how can i \"gc\" or \"prune\" objects related to a deleted remote?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-03-20T05:22:26Z","receivedAt":"2019-03-20T05:22:30Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 19, 2019 at 10:35:54AM +0100, Ævar Arnfjörð Bjarmason wrote:\n\n> > My guess is you forgot the tag? There's not a general solution there,\n> > because the tags all get intermingled. Git has no idea which ones came\n> > from which remote. However, if you have the commit id of an object you\n> > expect to be going away, you can use:\n> >\n> >   git for-each-ref --contains=$that_commit\n> \n> Not a general solution, but if you know you have one remote left, and\n> you don't have unpushed locally created tags, you can do a:\n> \n>     git fetch origin --prune --prune-tags\n\nGood call. I forgot that we even had --prune-tags.\n\n-Peff\n"}]}