什么可能导致git错误 - 损坏松散的对象?

时间:2014-10-28 01:53:45

标签: git

在执行git pull后遇到类似错误时,Stackoverflow上有很多关于如何修复存储库的帖子:

  
    

错误:对象文件.git / objects / 48 / 088f00d90b0d27de65336bb9ed9a75b0cfed33为空     致命:松散的物体48088f00d90b0d27de65336bb9ed9a75b0cfed33(存储在.git / objects / 48 / 088f00d90b0d27de65336bb9ed9a75b0cfed33中)已损坏

  

我很想知道的是:什么是导致此错误的事情的例子?

有些问题报告了系统重启或电池在git pull中间死机等问题。导致这个问题的这种中断是有道理的。

然后还有其他问题报告问题一再发生,例如在this post中,没有明确指示原因。

1 个答案:

答案 0 :(得分:1)

使用Git客户端执行对Git存储库的更改时,不应发生这些错误。从文档中,请参阅Object Storage以了解Git如何存储其对象:

  1. Git构造一个以对象类型开头的标题
  2. Git连接标题和原始内容,然后计算 新内容的SHA-1校验和
  3. Git使用zlib
  4. 压缩新内容

    腐败的松散物体是指其状态偏离此设计的任何物体(另请参阅What are the “loose objects” that the Git GUI refers to?)。

    除了系统重启或电池耗尽外,还有其他原因包括

    • 使用Git的错误第三方实现
    • 手动"克隆"使用rsync,scp或其他一些没有数据完整性检查的外部工具
    • 在Windows中复制和粘贴
    • 磁盘故障
    • 有时只有blue moon可以做到

    如果你有点好奇,试试这个人为的例子:

    $ git init bad-apple
    Initialized empty Git repository in /tmp/bad-apple/.git/
    
    $ cd bad-apple
    
    $ touch README; git add .; git commit -m "Add a transitional fossil"
    [master (root-commit) ca3ea96] Add a transitional fossil
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 README
    
    # Get the commit object id
    $ git rev-parse HEAD
    ca3ea9630c0f01afc286589c4072db9c43262d63
    
    # Git tries to help you not shoot yourself in the foot
    $ chmod +w .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63
    
    # Empty out the commit object file and you broke it
    $ truncate .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 --size 0
    error: object file .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 is empty
    error: object file .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63 is empty
    fatal: loose object ca3ea9630c0f01afc286589c4072db9c43262d63 (stored in .git/objects/ca/3ea9630c0f01afc286589c4072db9c43262d63) is corrupt