From: Fred Long Date: Thu, 13 Jun 2024 03:29:47 GMT Subject: Re: git fetch --prune fails with "fatal: bad object" Message-ID: In-Reply-To: <20240611073134.GE3248245@coredump.intra.peff.net> On 6/11/2024 12:31 AM, Jeff King wrote: > 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 Yes, and your solution is better than a newbie like me could have figured out, which is why I have been arguing for a simple documented command that people like me can run.