Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push error: object file is empty/loose object is corrupt

Tags:

git

I was attempting to perform a git commit using Git Gui. I staged a few files, and then my computer suddenly shut off due to low battery. I plugged it in, turned it back on, and committed the files I wanted to. Then I ran git push, like I've done a million times before with no issues, and this time I got the following error:

Counting objects: 8, done.
error: object file .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32 is empty
Compressing objects: 100% (4/4), done.
error: object file .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32 is empty
fatal: loose object b560c934f6bad40f4f246973afc0139ed91a2d32 (stored in .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32) is corrupt
error: failed to push some refs to '[email protected]:joemorano/app.git'

Could this have been caused by the computer shutting off before I could perform the first commit?

Right before all this happened, I apparently corrupted the production version of my app by running bundle install as root on my server, and now everything on the server is messed up, but I don't see how that could affect the local version. I never did git pull or anything like that.

Anyone encounter this error before?

like image 755
Joe Morano Avatar asked May 19 '16 02:05

Joe Morano


2 Answers

Step 1: Make a backup of .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.):

cp -a .git .git-old

Step 2: Run

git fsck --full

you will get this error message

For example: error: object file .git/objects/0A/dsdadadadaaeer4r3434343434334f is empty

Step 3: Remove the above empty file this is in your .git/objects/ folder. Continue deleting the empty files.

Step 4: After deleting all of the empty files, now run

git fsck --full

Step 5: Try git reflog. Fail because HEAD is broken.

Step 6: Manually get the reflog:

git log origin/master..HEAD

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:

git show commit-id 

Step 8: So now we need to point HEAD to commit-id

git update-ref HEAD commit-id

Hope this will work for you.

like image 50
Akshay Borade Avatar answered Nov 19 '22 13:11

Akshay Borade


... failed to push some refs to '[email protected]:joemorano/app.git'

Could this have been caused by the computer shutting off before I could perform the first commit?

Definitely, yes.

Anyone encounter this error before?

Repair corrupted git repository

See also: How to fix corrupted git repository?

In this case, since you (presumably) have a non-corrupt backup on bitbucket, I'd start by cloning that to a fresh (good) clone, then see if I could recover any intermediate commits and files from the existing (bad) clone and/or its work-tree, putting them into the new (good) clone. Once you have recovered whatever is recoverable from the bad clone, you can abandon or delete it. (Depending on your computer and its file system checking and repair tools, you might want to run those as well, perhaps before doing anything else at all.)

like image 6
torek Avatar answered Nov 19 '22 12:11

torek