如何恢复受硬盘故障损坏的Git对象?

编程入门 行业动态 更新时间:2024-10-18 03:23:56
本文介绍了如何恢复受硬盘故障损坏的Git对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了硬盘故障,导致Git存储库的某些文件损坏。当运行 git fsck --full 时,我得到以下输出:

错误:.git / objects / pack / pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack SHA1校验和不匹配错误:索引CRC错误对象6c8cae4994b5ec7891ccb1527d30634997a978ee from .git / objects / pack / pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack at 97824129 error :inflate:数据流错误(无效的代码长度设置)错误:无法从偏移97824129 错误:inflate:数据流错误(无效)中.git / objects / pack / pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack中解压缩6c8cae4994b5ec7891ccb1527d30634997a978ee存储块长度)错误:未能从.git / objects / pack / pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack 读取对象0dcf6723cc69cc7f91d4a7432d0f1a1f05e77eaa偏移量276988017致命:对象0dcf6723cc69cc7f91d4a7432d0f1a1f05e77eaa已损坏

我有版本库的备份,但是只有备份包含包文件已损坏。所以我认为我必须找到一种方法来从不同的备份中检索单个对象,并以某种方式指示Git生成一个只包含正确对象的新包。

你能请给我提示如何修复我的存储库?

解决方案

在以前的某些备份中,您的不良对象可能已打包到不同的文件或者可能是松散的物体。所以你的对象可能会被恢复。

看起来你的数据库中有一些坏对象。所以你可以用手工的方式来做。

由于 git hash-object , git mktree 和 git commit-tree 不要编写对象,因为它们在包中找到,然后开始执行此操作:

mv .git / objects / pack / *< somewhere> for i in< somewhere> / *。pack;做 git unpack-objects -r< $ i 完成 rm< somewhere> / *

从存储库中移出,并在其中解压缩;只有好的对象现在在数据库中)

您可以这样做:

git cat-file -t 6c8cae4994b5ec7891ccb1527d30634997a978ee

<

如果类型是blob:从以前的备份中检索文件的内容(使用 git show 或 git cat-file 或 git unpack-file ;那么您可以 git hash-object -w 来重写当前仓库中的对象。

如果类型是tree:可以使用 git ls-tree 从先前的备份中恢复树;然后 git mktree 将其重新写入当前的存储库。 / p>

如果类型为commit:与相同,git show , git cat-file 和 git commit-tree 。

当然,我会在开始这个过程之前备份原始的工作副本。

另外,请看如何恢复损坏的Blob对象。

I have had a hard disk failure which resulted in some files of a Git repository getting damaged. When running git fsck --full I get the following output:

error: .git/objects/pack/pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack SHA1 checksum mismatch error: index CRC mismatch for object 6c8cae4994b5ec7891ccb1527d30634997a978ee from .git/objects/pack/pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack at offset 97824129 error: inflate: data stream error (invalid code lengths set) error: cannot unpack 6c8cae4994b5ec7891ccb1527d30634997a978ee from .git/objects/pack/pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack at offset 97824129 error: inflate: data stream error (invalid stored block lengths) error: failed to read object 0dcf6723cc69cc7f91d4a7432d0f1a1f05e77eaa at offset 276988017 from .git/objects/pack/pack-6863e0a0e4b4ded6090fac5d12eba6ca7346b19c.pack fatal: object 0dcf6723cc69cc7f91d4a7432d0f1a1f05e77eaa is corrupted

I have backups of the repository, but the only backup that includes the pack file has it already damaged. So I think that I have to find out a way to retrieve the single objects from different backups and somehow instruct Git to produce a new pack with only correct objects.

Can you please give me hints how to fix my repository?

解决方案

In some previous backups, your bad objects may have been packed in different files or may be loose objects yet. So your objects may be recovered.

It seems there are a few bad objects in your database. So you could do it the manual way.

Because of git hash-object, git mktree and git commit-tree do not write the objects because they are found in the pack, then start doing this:

mv .git/objects/pack/* <somewhere> for i in <somewhere>/*.pack; do git unpack-objects -r < $i done rm <somewhere>/*

(Your packs are moved out from the repository, and unpacked again in it; only the good objects are now in the database)

You can do:

git cat-file -t 6c8cae4994b5ec7891ccb1527d30634997a978ee

and check the type of the object.

If the type is blob: retrieve the contents of the file from previous backups (with git show or git cat-file or git unpack-file; then you may git hash-object -w to rewrite the object in your current repository.

If the type is tree: you could use git ls-tree to recover the tree from previous backups; then git mktree to write it again in your current repository.

If the type is commit: the same with git show, git cat-file and git commit-tree.

Of course, I would backup your original working copy before starting this process.

Also, take a look at How to Recover Corrupted Blob Object.

更多推荐

如何恢复受硬盘故障损坏的Git对象?

本文发布于:2023-06-06 01:39:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/531175.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:故障   对象   硬盘   Git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!