Git仓库损坏(不正确的标题检查;松散的对象已损坏) [英] Git repository corrupt (incorrect header check; loose object is corrupt)

查看:2378
本文介绍了Git仓库损坏(不正确的标题检查;松散的对象已损坏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天晚上我写了一个提交信息时遇到了电源故障。当我启动机器时,我无法完成提交。我运行了 git reset ,添加了更改后的文件,然后重试,得到了这个结果:

 %git commit 
错误:inflate:数据流错误(不正确的标题检查)
错误:无法解压a94406345ac44982b00cf57b4b9660a35436637f标题
致命:a94406345ac44982b00cf57b4b9660a35436637f不是有效对象

git fsck 显示以下内容:

 %git fsck --full 
检查对象目录:100%(256/256),done。
错误:inflate:数据流错误(不正确的头文件检查)
错误:无法解压4346883490a0990e68db0187241abc1642765a73头文件
错误:膨胀:数据流错误(不正确的头文件检查)
致命:对象4346883490a0990e68db0187241abc1642765a73(保存在.git / objects / 43 / 46883490a0990e68db0187241abc1642765a73中)已损坏

我注意到消息是抱怨不同的对象。



我搜索了这个和网页,并尝试了一些不同的东西,但没有用。




  • 我没有最近的备份副本。

  • 将存储库克隆到另一个目录中并没有帮助;新的存储库展现了完全相同的问题。 code>。所有其他的git命令似乎正常工作。



如何判断出现问题并修复它?



编辑: git log 输出建议(只是前几行):

 %git log --oneline --decorate --all | head -n 8 
253b086(HEAD,new_tokenize)Normalized tokenizer接口略微$

d1e15ad(tag:v0.10)增加了具有尾调用语义的`if'形式
f94a992(tag :v0.9)已完成的环境
031116e修复了一行自身导致段错误的错误
3d8b09f添加了环境,定义和设置!
01cc624将符号表实现放入types.c中

这是一个小型的个人项目;我通常只是在(主)工作,但我当时正在做一个实验(new_tokenize)。 253b086是断电前最后一次成功的提交。

解决方案

看来,git为.git / objects创建了新文件提交,但没有成功写入他们。我通过一次删除一个并重新运行 git fsck --full 来找到下一个。我开始使用最初由 git fsck 报告的那个:

 %rm -f .git / objects / 43 / 46883490a0990e68db0187241abc1642765a73 
%git fsck --full
检查对象目录:100%(256/256),完成。
错误:inflate:数据流错误(不正确的标题检查)
错误:无法解压86e7247af5865e857a3b61eed99986e2d9538df1标题
错误:膨胀:数据流错误(不正确的标题检查)
致命:宽松对象86e7247af5865e857a3b61eed99986e2d9538df1(保存在.git / objects / 86 / e7247af5865e857a3b61eed99986e2d9538df1中)已损坏
%rm -f .git / objects / 86 / e7247af5865e857a3b61eed99986e2d9538df1
%git fsck --full
检查对象目录: 100%(256/256),完成。
错误:膨胀:数据流错误(不正确的标题检查)
错误:无法解压a94406345ac44982b00cf57b4b9660a35436637f标题
错误:膨胀:数据流错误(不正确的标题检查)
致命:宽松对象a94406345ac44982b00cf57b4b9660a35436637f(保存在.git / objects / a9 / 4406345ac44982b00cf57b4b9660a35436637f中)已损坏

等等。在 git fsck 出现干净之前,我删除了五个对象,对应于(正如我所想的)我尝试创建的提交中的五个文件。我猜文件历史根本没有损坏。



顺便说一下,我想到另一种似乎也适用的方法。 git clone 复制坏对象,但是 git push 不会。在备份之后,我创建了一个新的空的存储库(--bare,因为否则你不能推送给master),然后取消我的更改并将两个分支推入新的存储库。然后,它只是一个检查出来,并恢复从我的备份最新变化的问题。



如果有人关心这里的失败机制,仍然感兴趣。 / p>

I experienced a power failure yesterday evening while writing a commit message. When I booted the machine back up I couldn't complete the commit. I ran git reset, added back the changed files, and tried again, and got this:

% git commit
error: inflate: data stream error (incorrect header check)
error: unable to unpack a94406345ac44982b00cf57b4b9660a35436637f header
fatal: a94406345ac44982b00cf57b4b9660a35436637f is not a valid object

git fsck reveals the following:

% git fsck --full
Checking object directories: 100% (256/256), done.
error: inflate: data stream error (incorrect header check)
error: unable to unpack 4346883490a0990e68db0187241abc1642765a73 header
error: inflate: data stream error (incorrect header check)
fatal: loose object 4346883490a0990e68db0187241abc1642765a73 (stored in .git/objects/43/46883490a0990e68db0187241abc1642765a73) is corrupt

I notice the messages are complaining about different objects.

I searched SO and the Web and tried a few different things but to no avail.

  • I don't have a recent backup copy.
  • Cloning the repository into another directory doesn't help; the new repository exhibits the exact same problems.
  • git stash gives the same message as git commit. All the other git commands seem to work normally.

How can I tell what is wrong and fix it?

Edit: git log output as suggested (just the first few lines):

% git log --oneline --decorate --all |head -n 8
253b086 (HEAD, new_tokenize) Normalized tokenizer interface slightly
0f2425a (master) Added procs to eval layer
a4d4c22 Added procedures as a type
d1e15ad (tag: v0.10) Added `if' form with tail call semantics
f94a992 (tag: v0.9) Completed environments
031116e Fixed bug where # on a line by itself caused segfault
3d8b09f Added environments, define and set!
01cc624 Put symbol table implementation into types.c

This is a small personal project; I usually just work in (master) but I was doing an experiment at the time (new_tokenize). 253b086 was the last successful commit before the power failure.

解决方案

It appears that git created files in .git/objects for the new commit, but didn't successfully write to them. I solved it by deleting them one at a time and re-running git fsck --full to find the next one. I started with the one originally reported by git fsck:

% rm -f .git/objects/43/46883490a0990e68db0187241abc1642765a73
% git fsck --full
Checking object directories: 100% (256/256), done.
error: inflate: data stream error (incorrect header check)
error: unable to unpack 86e7247af5865e857a3b61eed99986e2d9538df1 header
error: inflate: data stream error (incorrect header check)
fatal: loose object 86e7247af5865e857a3b61eed99986e2d9538df1 (stored in .git/objects/86/e7247af5865e857a3b61eed99986e2d9538df1) is corrupt
% rm -f .git/objects/86/e7247af5865e857a3b61eed99986e2d9538df1
% git fsck --full
Checking object directories: 100% (256/256), done.
error: inflate: data stream error (incorrect header check)
error: unable to unpack a94406345ac44982b00cf57b4b9660a35436637f header
error: inflate: data stream error (incorrect header check)
fatal: loose object a94406345ac44982b00cf57b4b9660a35436637f (stored in .git/objects/a9/4406345ac44982b00cf57b4b9660a35436637f) is corrupt

And so on. I deleted five objects before git fsck came up clean, corresponding (as I suppose) to the five files in the commit I was trying to make. I guess that the file history was not corrupted at all.

Incidentally, I thought of another method that seems to work as well. git clone copies the bad objects, but git push does not. After backing up, I created a new empty repository (--bare, because otherwise you can't push to master), then unstaged my changes and pushed both branches into the new repository. Then it was just a matter of checking it out again and restoring the latest changes from my backups.

Still interested if anyone cares to shed light on the failure mechanism here.

这篇关于Git仓库损坏(不正确的标题检查;松散的对象已损坏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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