当我尝试提交更改时,我得到这个错误:

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 fsck检测到的各种空文件,然后运行一个简单的git拉。

我感到失望的是,现在即使文件系统实现了日志记录和其他“事务性”技术来保持文件系统正常运行,Git也会因为设备上的电源故障或空间问题而进入损坏状态(并且无法自行恢复)。

其他回答

在我的例子中,出现这个错误是因为我正在输入提交消息,而我的笔记本关机了。

我执行了以下步骤来修复错误:

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

Git对象文件已经损坏(正如在其他回答中指出的那样)。这可能发生在机器崩溃等情况下。

我也有同样的问题。在阅读了这里的其他顶级答案之后,我发现了修复损坏的Git存储库的最快方法,使用以下命令(在包含.git文件夹的Git工作目录中执行):

(请务必先备份Git存储库文件夹!)

find .git/objects/ -type f -empty | xargs rm
git fetch -p
git fsck --full

这将首先删除导致整个存储库损坏的所有空对象文件,然后从远程存储库获取缺失的对象(以及最新的更改),然后执行完整的对象存储检查。在这一点上,它应该成功而没有任何错误(尽管仍然可能有一些警告!)

PS:这个答案表明你有一个Git存储库的远程副本 在某个地方(例如在GitHub上),损坏的存储库是本地存储库,它绑定到仍然完整的远程存储库。如果不是这样,那么不要尝试用我推荐的方法来修复它。

这个问题的解决方法很简单

•找到那个文件

•就像我的情况一样

error: object file .git/objects/f1/a0e726cd3505a9be8dffaa78077dfe3a497eaf is empty
fatal: loose object f1a0e726cd3505a9be8dffaa78077dfe3a497eaf (stored in .git/objects/f1/a0e726cd3505a9be8dffaa78077dfe3a497eaf) is corrupt

然后直接删除 a0e726cd3505a9be8dffaa78077dfe3a497eaf

Or

rm .git/objects/f1/a0e726cd3505a9be8dffaa78077dfe3a497eaf

移动你的应用文件夹做一个备份,即mv app_folder app_folder_bk(它就像一个git stash) Git克隆your_repository 最后,打开一个合并工具(我在Linux上使用Meld diff查看器,在Windows上使用WinMerge),从右边(app_folder_bk)复制更改到左边(new app_folder)(这就像一个git stash应用)。

这是所有。也许这不是最好的方法,但我认为它很实用。

这解决了我的问题:

git stash
git checkout master
cd .git/ && find . -type f -empty -delete
git branch your-branch-name -D
git checkout -b your-branch-name
git stash pop