Re: git fetch --prune fails with "fatal: bad object"
- From
Jeff King <peff@peff.net>
- Date
- Jun 8, 2024, 11:20 UTC
- Message-ID
- <20240608112033.GB2966571@coredump.intra.peff.net>
- In-Reply-To
- <5469592f-69eb-b1da-1218-abeae88f7303@fastmail.fm>
On Thu, Jun 06, 2024 at 01:12:31PM -0700, Fred Long wrote:
Show 9 quoted lines
> Yeah, I saw that, and I think I know what's causing the problem. First I > create a bare mirror of AOSP with "repo init --mirror" and "repo sync", then > for all my different source trees I use "repo init --reference" to share > objects with the mirror using alternates files. Running "repo sync" on the > bare mirror works fine. The problem occurs when I run "repo sync" in one of > my source trees. Commits and refs have been deleted from the mirror, but the > refs are not deleted from the repos that point to the mirror. So it all > makes sense now. Still, I wish there were a simple command I could run to > remove the dangling refs.
Yep, that all makes sense.
As I said before, I don't think auto-deleting corrupted refs is great in general, just because it can make a bad situation worse. But if you want the foot-gun, here's a more complete script that you could run. It _just_ looks in refs/remotes/, which is perhaps a bit safer.
git for-each-ref --format='%(refname)' refs/remotes/ | git cat-file --batch-check='%(objectname)' | perl -alne 'print "delete $F[0]" if $F[1] eq "missing"' | tee /dev/stderr | git update-ref --stdin
-Peff