object file 相关错误

本地的repo在执行git loggit pull命令时出现了如下关于object file的错误:

git log 错误

>>>> $ git log
error: object file .git/objects/7b/40exxx is empty
error: object file .git/objects/7b/40exxx is empty
fatal: loose object 7b40exxx (stored in .git/objects/7b/40exxx) is corrupt

git pull 错误

>>>> $ git pull
error: object file .git/objects/7b/40exxx is empty
error: object file .git/objects/7b/40exxx is empty
remote: Counting objects: 479, done
remote: Finding sources: 100% (1388/1388)
error: object file .git/objects/7b/40exxx is empty
fatal: cannot read existing object info 40exxx
fatal: index-pack failed
warning: unable to unlink '(null)': Bad address

解决方法 Solution

1
2
3
4
5
6
7
8
cd <your_repo>

# 备份 .git
cp -r .git .git-bak

cd .git
find . -type f -empty -delete -print
git fsck --full

再次尝试git loggit pull命令。一切正常后删除备份 rm -r .git-bak