当我尝试提交更改时,我得到这个错误:
error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty
fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt
我尝试了我得到的 git fsck:
error: object file .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71 is empty
fatal: loose object 03dfd60a4809a3ba7023cbf098eb322d08630b71 (stored in .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71) is corrupt
如何解决这个错误?
在我的例子中,出现这个错误是因为我正在输入提交消息,而我的笔记本关机了。
我执行了以下步骤来修复错误:
git checkout -b backup-branch # Create a backup branch
git reset --hard HEAD~4 # Reset to the commit where everything works well. In my case, I had to back four commits in the head, that is until my head be at the point before I was typing the commit message. Before doing this step, copy the hash of the commits you will reset. In my case I copied the hash of the four last commits.
git cherry-pick <commit-hash> # Cherry pick the reset commits (in my case are four commits, so I did this step four times) from the old branch to the new branch.
git push origin backup-branch # Push the new branch to be sure everything works well
git branch -D your-branch # Delete the branch locally ('your-branch' is the branch with problem)
git push origin :your-branch # Delete the branch from remote
git branch -m backup-branch your-branch # Rename the backup branch to have the name of the branch that had the problem
git push origin your-branch # Push the new branch
git push origin :backup-branch # Delete the backup branch from remote