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

$ 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。

其他回答

我遵循了这里的许多其他步骤;Linus对如何查看git树/对象并找到缺失内容的描述尤其有用。git恢复损坏的blob

但最后,对我来说,由于部分磁盘故障,我有松散/损坏的树对象,并且树对象不容易恢复/不被那个文档覆盖。

最后,我将冲突的对象/<ha>/<hash>移出,并使用git unpack-objects与最新克隆的包文件一起使用。它能够恢复丢失的树对象。

仍然给我留下了许多悬空的斑点,这可能是解压缩以前存档的东西的副作用,并在这里的其他问题中解决

当我的系统崩溃时,我遇到了这种情况。我所做的是:

(请注意,您的损坏提交将丢失,但更改将保留。你可能必须在这个过程结束时重新创建这些提交)

备份代码。 转到您的工作目录并删除.git文件夹。 现在将远程复制到另一个位置,并在其中复制.git文件夹。 将其粘贴到工作目录中。 做你想做的事。

最好的办法可能是简单地从远程存储库(即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

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

在我的(Windows)机器决定重新启动后,我得到了这个错误。

谢天谢地,我的远程存储库是最新的,所以我只是做了一个新的Git克隆…

创建备份并将存储库克隆到一个新目录

cp -R foo foo-backup
git clone git@url:foo foo-new

(可选)如果你在不同的分支上工作,切换它。

cd foo-new
git checkout -b branch-name origin/branch-name

同步除.git目录外的更改

rsync -aP --exclude=.git foo-backup/ foo-new