每当我从我的遥控器,我得到以下关于压缩的错误。当我运行手动压缩,我得到相同的:
$ git gc
error: Could not read 3813783126d41a3200b35b6681357c213352ab31
fatal: bad tree object 3813783126d41a3200b35b6681357c213352ab31
error: failed to run repack
有人知道该怎么做吗?
从cat文件中我得到了这个:
$ git cat-file -t 3813783126d41a3200b35b6681357c213352ab31
error: unable to find 3813783126d41a3200b35b6681357c213352ab31
fatal: git cat-file 3813783126d41a3200b35b6681357c213352ab31: bad file
从git fsck中我得到了这个(不知道它是否真的相关):
$ git fsck
error: inflate: data stream error (invalid distance too far back)
error: corrupt loose object '45ba4ceb93bc812ef20a6630bb27e9e0b33a012a'
fatal: loose object 45ba4ceb93bc812ef20a6630bb27e9e0b33a012a (stored in .git/objects/45/ba4ceb93bc812ef20a6630bb27e9e0b33a012a) is corrupted
有人能帮我解读一下吗?
我刚遇到过这样的问题。我的特殊问题是由系统崩溃引起的,它破坏了最近的提交(因此也破坏了主分支)。我没有强迫自己,想要重新做出承诺。在我的特殊情况下,我可以这样处理:
Make a backup of .git/: rsync -a .git/ git-bak/
Check .git/logs/HEAD, and find the last line with a valid commit ID. For me, this was the second most recent commit. This was good, because I still had the working directory versions of the file, and so the every version I wanted.
Make a branch at that commit: git branch temp <commit-id>
re-do the broken commit with the files in the working directory.
git reset master temp to move the master branch to the new commit you made in step 2.
git checkout master and check that it looks right with git log.
git branch -d temp.
git fsck --full, and it should now be safe to delete any corrupted objects that fsck finds.
If it all looks good, try pushing. If that works,
这对我很管用。我怀疑这是一个相当常见的场景,因为最近的提交是最有可能被损坏的,但如果你丢失了一个更早的提交,你可能仍然可以使用这样的方法,小心地使用git cherrypick,并在.git/logs/HEAD中reflog。
我在写提交信息的时候电脑死机了。重新启动后,工作树就像我离开时一样,我能够成功提交我的更改。
然而,当我试图运行git状态时,我得到了
error: object file .git/objects/xx/12345 is empty
fatal: loose object xx12345 (stored in .git/objects/xx/12345 is corrupt
与大多数其他答案不同,我并没有试图恢复任何数据。我只是需要Git停止抱怨空对象文件。
概述
“目标文件”是Git对您所关心的实际文件的散列表示。Git认为它应该有一个/文件的散列版本。无论存储在.git/object/xx/12345中的是什么,修复这个错误基本上就是找出“松散对象”应该表示哪个文件的问题。
细节
可能的选择似乎是
删除空文件
将文件转换为Git可以接受的状态
方法1:删除目标文件
我尝试的第一件事就是移动object文件
mv .git/objects/xx/12345 ..
但这并没有起作用——Git开始抱怨断开的链接。关于方法二。
方法2:修复文件
Linus Torvalds写了一篇关于如何恢复目标文件的文章,为我解决了这个问题。这里总结了关键步骤。
$> # Find out which file the blob object refers to
$> git fsck
broken link from tree 2d9263c6d23595e7cb2a21e5ebbb53655278dff8
to blob xx12345
missing blob xx12345
$> git ls-tree 2d926
...
10064 blob xx12345 your_file.whatever
这告诉你空对象应该是哪个文件的哈希值。现在你可以修理了。
$> git hash-object -w path/to/your_file.whatever
在这样做之后,我检查了. Git /objects/xx/12345,它不再是空的,Git停止抱怨。