Re: git fetch --prune fails with "fatal: bad object"
On 6/8/2024 4:20 AM, Jeff King wrote:
Show 25 quoted lines
> On Thu, Jun 06, 2024 at 01:12:31PM -0700, Fred Long wrote:
>
>> 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
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
)