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

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文件损坏后,我也有同样的问题。

第一步,从项目的根文件夹。

find .git/objects -type f -empty -delete

然后是西梅和fetch…

git prune
git fetch --all --prune

然后做了一些回滚,然后就开始工作了。

其他回答

在一个脚本中

#! /bin/sh

# Save Git data
cp -r .git gitold

# Remove all empty Git object files
find .git -type f -empty -delete -print

# Get the current branch name
branchname=$(git branch --show-current)

# Get the latest commit hash
commit=$(tail -2 .git/logs/refs/heads/$branchname | awk '{ print $2 }' | tr -d '[:space:]')

# Set HEAD to this latest commit
git update-ref HEAD $commit

# Pull the latest changes on the current branch (considering remote is origin)
git pull origin $branchname

echo "If everything looks fine you remove the git backup running :\n\
      $ rm -rf gitold \n\
Otherwise restore it with: \n\
      $ rm -rf .git; mv gitold .git"

让我们简单点…只有在将源代码上传到远程Git存储库的情况下

备份你的。git文件夹 检查Git存储库 Git FSCK—满 删除空目标文件(全部) rm / 8 b / 61 d0135d3195966b443f6c73fb68466264c68e . /对象 再次检查Git存储库。 Git FSCK—满 从远程Git存储库中提取源代码 Git拉源主

我修复了我的git错误:对象文件是空的:

保存我上次成功提交/推送后编辑的所有文件的副本, 删除并重新克隆我的存储库, 用我编辑过的文件替换旧文件。

在这种情况下,我通过遵循这个问题来解决我的问题。

从存储库目录中删除。git文件夹。(为安全起见保留备份) 克隆我的回购在另一个目录。 从新的克隆目录复制.git文件夹。 粘贴到之前出现问题的目录中。

检查git状态,希望你能看到你所有的变化。现在你可以承诺并推进了。

这解决了我的问题:

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