每当我从我的遥控器,我得到以下关于压缩的错误。当我运行手动压缩,我得到相同的:

$ 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

有人能帮我解读一下吗?


当前回答

垃圾收集解决了我的问题:

git gc --aggressive --prune=now

它需要一段时间才能完成,但是每个松散的对象和/或损坏的索引都是固定的。

其他回答

对我来说,这是由于在做git推时发生的电源故障。

这些信息是这样的:

$ git status
error: object file .git/objects/c2/38824eb3fb602edc2c49fccb535f9e53951c74 is empty
error: object file .git/objects/c2/38824eb3fb602edc2c49fccb535f9e53951c74 is empty
fatal: loose object c238824eb3fb602edc2c49fccb535f9e53951c74 (stored in .git/objects/c2/38824eb3fb602edc2c49fccb535f9e53951c74) is corrupt

我尝试了git fsck之类的东西,但这没有帮助。 由于崩溃发生在git推送期间,它显然发生在客户端重写期间,发生在服务器更新之后。我环顾四周,发现c2388在我的例子中是一个提交对象,因为它是由.git/refs中的条目引用的。所以我知道,当我查看历史(通过web界面或第二个克隆)时,我将能够找到c2388。

在第二个克隆中,我执行了git log -n 2 c2388来识别c2388的前身。然后我手动修改了.git/refs/heads/master和.git/refs/remotes/origin/master作为c2388的前身,而不是c2388。 然后我可以进行git取回。 git获取失败了几次,因为空对象上的冲突。我删除了这些空对象,直到git获取成功。这已经修复了存储库。

在虚拟机上工作,在我的笔记本上,电池没电了,得到这个错误;

error: object file .git/objects/ce/theRef为空 文件.git/objects/ce/theRef是空的 (存储在.git/objects/ce/theRef中)已损坏

我设法让回购工作再次只有2个命令,而没有丢失我的工作(修改文件/未提交的更改)

find .git/objects/ -size 0 -exec rm -f {} \;
git fetch origin

在那之后,我运行了git状态,回购很好,有我的更改(等待提交,现在就做…)

Git版本1.9.1

请记住备份您所记得的所有更改,以防此解决方案不起作用,需要更激进的方法。

最好的办法可能是简单地从远程存储库(即GitHub或其他)重新克隆。不幸的是,你将失去任何未推送的提交和隐藏的更改,但你的工作副本应该保持完整。

首先对本地文件进行备份。然后从你的工作树的根开始:

rm -fr .git
git init
git remote add origin [your-git-remote-url]
git fetch
git reset --mixed origin/master
git branch --set-upstream-to=origin/master master

然后根据需要提交任何更改过的文件。

我刚遇到过这样的问题。我的特殊问题是由系统崩溃引起的,它破坏了最近的提交(因此也破坏了主分支)。我没有强迫自己,想要重新做出承诺。在我的特殊情况下,我可以这样处理:

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。

user1055643的答案缺少最后一步:

rm -fr .git
git init
git remote add origin your-git-remote-url
git fetch
git reset --hard origin/master
git branch --set-upstream-to=origin/master master