Search code examples
git

git gc: error: Could not read 0000000000000000000000000000000000000000


git gc
error: Could not read 0000000000000000000000000000000000000000
Enumerating objects: 147323, done.
Counting objects: 100% (147323/147323), done.
Delta compression using up to 4 threads
Compressing objects: 100% (36046/36046), done.
Writing objects: 100% (147323/147323), done.
Total 147323 (delta 91195), reused 147323 (delta 91195), pack-reused 0

What is going on here? Should I worry or ignore the the problem?

For example git gc --help and similar have nothing that appears to explain the problem.

git fsck report

I am running git version 2.35.1 on Lubuntu 20.04.


Solution

  • This error is harmless in the sense that it does not indicate a broken repository. It is a bug that was introduced in Git 2.35 and that should be fixed in later releases. [Edit: This regression was fixed in Git 2.36.0.]

    The worst that can happen is that git gc does not prune all objects that are referenced from reflogs. The error is triggered by an invocation of git reflog expire --all that git gc does behind the scenes.

    The trigger are empty reflog files in the .git/logs directory structure that were left behind after a branch was deleted. As a workaround you can remove these empty files. This command lets you find them and check their size:

    find .git/logs -type f -size 0c | xargs ls -ld
    

    Pick only the files that do not correspond to a branch. (Also, I am uncertain about the operation of -size 0c, hence, do make sure not to remove all the listed files blindly, but only those that have no corresponding branch and are actually empty.)

    This issue was forwarded to git mailing list based on this SO question and is being solved.