4

我有一个损坏的松散物体。

我尝试了结帐、还原、变基,并且可能很少有其他事情可以进行原始提交。在每种情况下,我都跑了git fsck,但仍然遇到同样的问题:

> git fsck 
error: corrupt loose object '25a196217ebb6e341909205575f491022eafc4d9'
fatal: loose object 25a196217ebb6e341909205575f491022eafc4d9 (stored in .git/objects/25/a196217ebb6e341909205575f491022eafc4d9) is corrupt

有没有办法摆脱损坏的对象而无需简单地删除.git?我没有另一个备份,所以我无法替换损坏的对象。

移动目录后,这个 git“错误:损坏的松散对象”引发了一个更狭窄的问题

更新(1):

> git gc
Counting objects: 747, done.
Delta compression using up to 8 threads.
error: corrupt loose object '25a196217ebb6e341909205575f491022eafc4d9'
fatal: loose object 25a196217ebb6e341909205575f491022eafc4d9 (stored in .git/objects/25/a196217ebb6e341909205575f491022eafc4d9) is corrupt
error: failed to run repack

更新(2): 这也不起作用从 git 存储库中删除文件(历史记录)

更新(3): 克隆不起作用:

> git clone ../dynamicsCode_good/ .
Cloning into ....
done.
error: corrupt loose object '25a196217ebb6e341909205575f491022eafc4d9'
fatal: loose object 25a196217ebb6e341909205575f491022eafc4d9 (stored in .git/objects/25/a196217ebb6e341909205575f491022eafc4d9) is corrupt

这 。目录为空

更新(4): 删除损坏的对象。

> git --version
git version 1.7.5.4


> rm -f .git/objects/25/a196217ebb6e341909205575f491022eafc4d9
13:42:57 ~/Dropbox/work/dev/dynamicsCode_torek 
> git fsck --full
missing blob 25a196217ebb6e341909205575f491022eafc4d9
dangling tree 64a970c878fef7deeeb4ce2ffc5e6234a72894ad
dangling tree 528e6c121fb8e56097462b2ebb9ec4de66388ce2

第一个(初始)评论。此评论甚至没有损坏的文件。

> git log |tail -5
commit 150ceebafb9c20769386cc7ffba07f6e6565fae6
Author: Kirill ...gmail.com>
Date:   Tue Sep 27 22:51:15 2011 -0400

    state takes input as input
checkout:

> git checkout -b 150ceebafb9c20769386cc7ffba07f6e6565fae6
Switched to a new branch '150ceebafb9c20769386cc7ffba07f6e6565fae6'

> git gc
Counting objects: 783, done.
error: unable to find 25a196217ebb6e341909205575f491022eafc4d9
Compressing objects: 100% (776/776), done.
fatal: unable to read 25a196217ebb6e341909205575f491022eafc4d9
error: failed to run repack
> git fsck --full
broken link from    tree 4668817140320ad2e04aa946d95dec2c3885d97b
              to    blob 25a196217ebb6e341909205575f491022eafc4d9
missing blob 25a196217ebb6e341909205575f491022eafc4d9
dangling tree 64a970c878fef7deeeb4ce2ffc5e6234a72894ad
dangling tree 528e6c121fb8e56097462b2ebb9ec4de66388ce2

我还尝试解压缩.git/objects/pack/目录中唯一的对象。没有帮助。

我还将这个状态克隆到一个新目录中:

> git gc
Counting objects: 662, done.
error: unable to find 25a196217ebb6e341909205575f491022eafc4d9
Compressing objects: 100% (656/656), done.
fatal: unable to read 25a196217ebb6e341909205575f491022eafc4d9
error: failed to run repack
14:40:34 ~/Dropbox/work/dev/dynamicsCode_torek_commit_clone 
> git fsck 
broken link from    tree b5ab6b287804d5069a3c8648ace38d9d9feac1a5
              to    blob 25a196217ebb6e341909205575f491022eafc4d9
dangling commit dad8edc620248d3911b7b1c0a99608a64e0288a3
missing blob 25a196217ebb6e341909205575f491022eafc4d9
dangling tree 64a970c878fef7deeeb4ce2ffc5e6234a72894ad
dangling commit ae2b2a9edb744d9e91aa78891c849d5a0040ea94
dangling commit 32ed79bd4ac70b118d046cb6093a4710562e95ba
dangling commit 7e45ef0c6ffc46401b1f82bcbf0f7e843abf9e31
dangling tree 528e6c121fb8e56097462b2ebb9ec4de66388ce2
14:40:40 ~/Dropbox/work/dev/dynamicsCode_torek_commit_clone 
> git branch 
* 150ceebafb9c20769386cc7ffba07f6e6565fae6

也没有帮助。

损坏的文件tags来自 ctags。我不需要它。奇怪的是,没有那个文件我就无法重建 git。最重要的是,从我所有的研究来看,我既看不出它是如何做到的,也看不出为什么它不可能。

更新(5): 结帐无分支

> git checkout 150ceebafb9c20769386cc7ffba07f6e6565fae6
Note: checking out '150ceebafb9c20769386cc7ffba07f6e6565fae6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 150ceeb... state takes input as input
16:41:40 ~/Dropbox/work/dev/dynamicsCode_torek_commit 
> git fsck --full
broken link from    tree 4668817140320ad2e04aa946d95dec2c3885d97b
              to    blob 25a196217ebb6e341909205575f491022eafc4d9
missing blob 25a196217ebb6e341909205575f491022eafc4d9
dangling tree 64a970c878fef7deeeb4ce2ffc5e6234a72894ad
dangling tree 528e6c121fb8e56097462b2ebb9ec4de66388ce2
4

1 回答 1

2

如果您手动删除损坏的对象,git 通常会让您处理其他所有问题。我故意破坏了一个 git blob(只是在前面强制了几个坏字节)并得到了以下信息:

$ git fsck
fatal: object bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad is corrupted
$ git gc
Counting objects: 23, done.
error: unable to unpack bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad header
error: inflateEnd: failed
Delta compression using up to 2 threads.
Compressing objects: 100% (12/12), done.
fatal: object bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad is corrupted
error: failed to run repack
$ git fsck --full
fatal: object bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad is corrupted
$ rm -f .git/objects/bd/1b260b0ef92d1a219e1183953fa1ac7cdb4cad
$ git fsck --full
broken link from    tree a3070cb66fd169e1443867a8bb137a44103c9f24
              to    blob bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad
missing blob bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad
$ git cat-file -p 2418b6ba8fd0289933c9351260a272b8e410867f
tree a3070cb66fd169e1443867a8bb137a44103c9f24
parent 8d945134b0cead535d66af29c8eb4228b5dc3763
author [redacted] 1333789753 -0600
committer [redacted] 1333789753 -0600

test corrupted object
$ git checkout 2418b6ba8fd0289933c9351260a272b8e410867f
error: git checkout-index: unable to read sha1 file of morefile (bd1b260b0ef92d1a219e1183953fa1ac7cdb4cad)
D   morefile
Note: checking out '2418b6ba8fd0289933c9351260a272b8e410867f'.

You are in 'detached HEAD' state. ...

请注意,在此过程中,它会将分支重新指向master之前的“良好”提交(不是立即提交的,我不知道为什么),因此您可能必须修复您的提交历史等。但一切都是那里,除了丢失的文件“morefile”,我损坏了它的blob。(我从我预先制作的备份副本中恢复了它,甚至能够用 . 取回文件git checkout -- morefile。你可以mv在某个地方找到损坏的 blob,看看你是否可以从中恢复一些数据。)

我当然会先备份损坏的 git 存储库,以防万一。:-)

于 2012-04-07T09:24:35.350 回答