什么可能会导致git错误 - 损坏松散的对象? [英] What might cause a git error - corrupt loose object?

查看:486
本文介绍了什么可能会导致git错误 - 损坏松散的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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


我很想知道的是:什么是会导致此错误开始的事情的示例?

有些问题报告像系统重新启动或电池在中间死亡的git拉。造成这个问题的中断是有道理的。

然后还有其他问题反映出问题不断发生,例如这篇文章,并没有明确的指示说明原因。

解决方案

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


  1. Git构造一个以对象类型开头的头文件
  2. Git连接标题和原始内容,然后计算
    新内容的SHA-1校验和

  3. Git使用zlib压缩新内容

损坏的松散对象是状态偏离此设计的任何对象(另见什么是Git GUI引用的松散对象?)。



除了系统重新启动或电池耗尽,其他原因还包括使用错误的第三方的


  • 使用rsync,scp或其他外部工具手动克隆Git的实现

  • 没有数据完整性检查

  • 在Windows中复制和粘贴

  • 磁盘失败
  • 有时只是一个 blue moon 可以做到这一点


如果您好奇,试试这个人为的例子:

  $ git init bad-apple 
在/tmp/bad-apple/.git/中初始化空的Git存储库

$ cd坏苹果

$ touch自述文件; git add。; git commit -m添加过渡化石
[master(root-commit)ca3ea96]添加一个过渡化石
1个文件已更改,0个插入(+),0个删除( - )
创建模式100644自述文件

#获取提交对象ID
$ git rev-parse HEAD
ca3ea9630c0f01afc286589c4072db9c43262d63

#Git试图帮助您不拍摄自己在脚下
$ chmod + w .git / objects / ca /​​ 3ea9630c0f01afc286589c4072db9c43262d63

#清空提交对象文件,并且破坏它
$ truncate .git / objects / ca / 3ea9630c0f01afc286589c4072db9c43262d63 --size 0
错误:目标文件.git / objects / ca /​​ 3ea9630c0f01afc286589c4072db9c43262d63为空
错误:目标文件.git / objects / ca /​​ 3ea9630c0f01afc286589c4072db9c43262d63为空
致命:松散对象(保存在.git / objects / ca /​​ 3ea9630c0f01afc286589c4072db9c43262d63中)已损坏


There are many posts here on Stackoverflow about how to fix your repository when you come across an error like this after doing a git pull:

error: object file .git/objects/48/088f00d90b0d27de65336bb9ed9a75b0cfed33 is empty fatal: loose object 48088f00d90b0d27de65336bb9ed9a75b0cfed33 (stored in .git/objects/48/088f00d90b0d27de65336bb9ed9a75b0cfed33) is corrupt

What I'm curious to know is: what are examples of things that would cause this error to begin with?

Some questions report things like their system rebooting or their battery dying in the middle of a git pull. This interruption causing the issue makes sense.

Then there are other questions who report that the issue repeatedly happening, such as in this post, with no clear indicator as to why.

解决方案

These errors should not happen when changes to the Git repository are carried out using the Git client. From the documentation, see Object Storage to learn how Git stores its objects:

  1. Git constructs a header that starts with the type of the object
  2. Git concatenates the header and the original content and then calculates the SHA-1 checksum of that new content
  3. Git compresses the new content with zlib

A corrupt loose object is any object whose state deviates from this design (See also What are the "loose objects" that the Git GUI refers to?).

Besides a system reboot or a dying battery, other reasons include

  • using a buggy third-party implementation of Git
  • manually "cloning" using rsync, scp, or some other external tool without data integrity checks
  • copying and pasting in Windows
  • disk failure
  • sometimes just a blue moon could do it

If you're curious, try this contrived example:

$ 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

这篇关于什么可能会导致git错误 - 损坏松散的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆