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

$ 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/objects/中找不到它的名字,它可能已经被[打包][包]以节省空间。)

其他回答

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

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

我也有同样的问题(不知道为什么)。

此修复需要访问未损坏的存储库远程副本,并将保持本地工作副本的完整性。

但它也有一些缺点:

您将丢失任何未推送的提交记录,并且必须重新提交它们。 你会丢失所有的钱。

修复

从repo上面的父目录执行这些命令(将'foo'替换为项目文件夹的名称):

创建损坏目录的备份: cp -R foo foo-backup 创建远程存储库的新克隆到一个新目录: Git克隆Git @www.mydomain.de:foo foo-newclone 删除损坏的.git子目录: Rm -rf foo/.git 将新克隆的.git子目录移到foo中: mv foo-newclone /。git foo 删除临时新克隆的其余部分: Rm -rf foo-newclone

在Windows上,你需要使用:

copy而不是cp -R rmdir /S代替rm -rf 移动而不是mv

现在foo恢复了它原来的.git子目录,但所有的本地更改仍然在那里。Git状态、提交、拉取、推送等再次正常工作。

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

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。

这里有个箱子。碰巧的是,问题是损坏文件的所有权是root而不是我们的正常用户。这是由于在有人执行了“sudo su——”之后在服务器上进行的提交造成的。

首先,用以下方法识别损坏的文件:

$> git fsck --full

你应该会收到这样的回答:

fatal: loose object 11b25a9d10b4144711bf616590e171a76a35c1f9 (stored in .git/objects/11/b25a9d10b4144711bf616590e171a76a35c1f9) is corrupt

进入损坏文件所在的文件夹,并执行以下操作:

$> ls -la

检查损坏文件的所有权。如果这是不同的,只要回到你的回购的根,并执行:

$> sudo chown -R YOURCORRECTUSER:www-data .git/

希望能有所帮助!

有同样的问题后,我的linux薄荷崩溃,我按下电源按钮关闭我的笔记本电脑,这就是为什么我的。git是腐败的

find .git/objects/ -empty -delete

在那之后,我得到致命错误:坏对象头。我刚刚重新初始化了我的git

git init

并从远程repo获取

git fetch

要检查git,请使用

git status

又是工作。我不会丢失局部更改,所以我可以在不重写代码的情况下提交