From: Jeff King Date: Tue, 11 Jun 2024 07:31:34 GMT Subject: Re: git fetch --prune fails with "fatal: bad object" Message-ID: <20240611073134.GE3248245@coredump.intra.peff.net> In-Reply-To: <5247e0cc-ef0e-558a-7e06-5a7425a52329@fastmail.fm> On Sat, Jun 08, 2024 at 02:02:52PM -0700, Fred Long wrote: > > 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 > > > Thanks. Here's what I have been using: > > git fsck |& grep "invalid sha1 pointer" | ( >     while read err ref rest >     do >         ref=${ref%:} >         echo got $ref, removing .git/$ref >         rm .git/$ref >     done > ) Parsing fsck's errors should be OK, I think, but your "rm" won't be reliable. If the ref is packed, then it needs to be removed from .git/packed-refs, too. Calling "git update-ref -d $ref" should work, even for a broken ref. -Peff