How to Solve git loose object Error (Three Methods)

description

I don’t know what’s going on. Recently, the following errors have appeared two or three times in a row, git pulland they will appear every time . I searched the Internet. Similar problems are very common. Each has its own solution.

Error message:

error: object file .git/objects/40/bda4e3b79c3d7bf598df31d9e68470f97a3f79 is empty
fatal: loose object 40bda4e3b79c3d7bf598df31d9e68470f97a3f79 (stored in .git/objects/40/bda4e3b79c3d7bf598df31d9e68470f97a3f79) is corrupt

Solution

The solution here is mainly for the case of uncommitted code . The following commands are all used under ubuntu, and the main commands are different under win.

(1) Re-cloning method

This is on stackoverflow.com, and everyone likes it a lot.

Note : This method will lose your local unpush submissions and changes, as well as all stash, and you need to resubmit after processing. foo is the local version library.

cp -R foo foo-backup
git clone [email protected]:foo foo-newclone
rm -rf foo/.git
mv foo-newclone/.git foo
rm -rf foo-newclone

(2) reflog method (not verified)

I haven’t tried this method for the time being, I hope it works.

rm .git/objects/40/bda4e3b79c3d7bf598df31d9e68470f97a3f79
git fsck --full
git reflog

(3) Fetch method (not verified)

Special note : This is similar to the first method above, but the domestic document is much larger and the local version library is backed up by one step, causing the loss of your unpushed work.

cp -R foo foo-backup 
rm -fr .git
git init
git remote add origin [your-git-remote-url]
git fetch
git reset --mixed origin/master 
git branch --set-upstream-to=origin/master master 

Similar Posts: