If you ever encountered the following issue, keep reading to fix it:
1$ git status
2error: object file .git/objects/42/123456789abcde123456789abcde is empty
3error: object file .git/objects/42/123456789abcde123456789abcde is empty
4fatal: loose object 123456789abcde123456789abcde (stored in .git/objects/42/123456789abcde123456789abcde) is corrupt
5$ git pull
6error: object file .git/objects/42/123456789abcde123456789abcde is empty
7fatal: loose object 123456789abcde123456789abcde (stored in .git/objects/42/123456789abcde123456789abcde) is corrupt
Navigate to the root of your git repo directory (the root should contain a
.git
folder, checkls -la
and look for the.git
folder at the top):Run the following command:
1find .git/objects -size 0 -delete
find
looks for all files in the directory.git/objects
with size0
and deletes themRun
git pull
and check if the output is correct. If it is, you removed all corrupted objects and therefore fixed the issue.
Tip
If this error keeps happening, consider making a backup of the files in your repo without the.git
directory and clone a clean repo from the remote.
After that replace the contents with your backup and commit + push the changes to the remote.