When I try to commit changes, I get this error:
error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty
fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt
I tried git fsck I’ve got:
error: object file .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71 is empty
fatal: loose object 03dfd60a4809a3ba7023cbf098eb322d08630b71 (stored in .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71) is corrupt
How can I solve this error?
I had a similar problem. My laptop ran out of battery during a Git operation. Boo.
I didn’t have any backups. (N.B. Ubuntu One is not a backup solution for Git; it will helpfully overwrite your sane repository with your corrupted one.)
To the Git wizards, if this was a bad way to fix it, please leave a comment. It did, however, work for me… at least temporarily.
Step 1: Make a backup of folder .git (in fact I do this in between every step that changes something, but with a new copy-to name, e.g., .git-old-1, .git-old-2, etc.):
Step 2: Run
git fsck --fullStep 3: Remove the empty file. I figured what the heck; it’s blank anyway.
Step 3: Run
git fsckagain. Continue deleting the empty files. You can alsocdinto the.gitdirectory and runfind . -type f -empty -delete -printto remove all empty files. Eventually Git started telling me it was actually doing something with the object directories:Step 4: After deleting all of the empty files, I eventually came to
git fsckactually running:Step 5: Try
git reflog. Fail because my HEAD is broken.Step 6: Google. Find this. Manually get the last two lines of the reflog:
Step 7: Note that from Step 6 we learned that the HEAD is currently pointing to the very last commit. So let’s try to just look at the parent commit:
It worked!
Step 8: So now we need to point HEAD to 9f0abf890b113a287e10d56b66dbab66adc1662d.
Which didn’t complain.
Step 9: See what fsck says:
Step 10: The invalid sha1 pointer in cache-tree seemed like it was from a (now outdated) index file (source). So I killed it and reset the repository.
Step 11: Looking at the fsck again…
The dangling blobs are not errors. I’m not concerned with master.u1conflict, and now that it is working I don’t want to touch it anymore!
Step 12: Catching up with my local edits: