Re: git fetch --prune fails with "fatal: bad object"
- From
- Fred Long <fred_long@fastmail.fm>
- Date
- Jun 13, 2024, 03:29 UTC
- Message-ID
- <fbe6ae6c-a89b-ae71-2474-10ac3afd0766@fastmail.fm>
- In-Reply-To
- <20240611073134.GE3248245@coredump.intra.peff.net>
On 6/11/2024 12:31 AM, Jeff King wrote:
Show 24 quoted lines
> 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.
>
> -PeffYes, 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.