如何修复坏的 git 树对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9005756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:23:20  来源:igfitidea点击:

How to fix a bad git tree object

gitversion-controlrepository

提问by Flupkear

I have a local copy of a repository that not longer have any remote associated to it. I'm trying to push this repo into a new remote however everytime I get this message:

我有一个存储库的本地副本,该副本不再与任何远程关联。我正在尝试将此存储库推送到新的遥控器中,但是每次收到此消息时:

error: Could not read 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790
fatal: bad tree object 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790

I read in similar questions here that one way to fix it is retrieving this object from other copies of the repository or doing a hard reset. I can't do any of both since I don't have another copy of this repo.

我在这里读到类似的问题,修复它的一种方法是从存储库的其他副本中检索此对象或进行硬重置。我不能同时做任何一个,因为我没有这个 repo 的另一个副本。

Is there a way to simply remove this commit or some other kind of solution that will allow me to push the repo to the new remote keeping history?

有没有办法简单地删除这个提交或其他类型的解决方案,让我将 repo 推送到新的远程保存历史记录?

回答by Max Leske

To actually fix the problem and not lose any data (provided that that tree is the only missing object, which I doubt) you could try this:

要真正解决问题而不丢失任何数据(假设该树是唯一丢失的对象,我对此表示怀疑)您可以尝试以下操作:

  1. checkout the parent commit of the commit with the concerning tree
  2. try git cat-file -pwith the name of the problematic commit to see what the commit message says (hopefully it will tell you what changed)
  3. now you might be able to determine the changes that were made and from this the directory structure can hopefully be inferred.
  4. if 3 worked, then you can create your tree manually using a text editor and a zlib compressor. The entries in the tee file will be other tree objects or blobs. Hopefully most of the files and folders are shared (have no changes) between the two commits. This will allow you to reuse most of the entries from the tree object of the checked out commit.
  1. 使用相关树检出提交的父提交
  2. 尝试使用有问题的提交的名称git cat-file -p以查看提交消息的内容(希望它会告诉您发生了什么变化)
  3. 现在您可能能够确定所做的更改,并且可以从中推断出目录结构。
  4. 如果 3 有效,那么您可以使用文本编辑器和 zlib 压缩器手动创建树。tee 文件中的条目将是其他树对象或 blob。希望大多数文件和文件夹在两次提交之间共享(没有更改)。这将允许您重用检出提交的树对象中的大部分条目。

回答by Ankish Jain

Just Quit the applcation with which you accessing git and restart . Worked for me for xcode-iOS.

只需退出您访问 git 的应用程序并重新启动。对我来说有效过 xcode-iOS。

回答by axsuul

I had this problem. Restarting my computer actually fixed it so please try it first before doing anything else. Or maybe I just got lucky but worth a shot!

我有这个问题。重新启动我的计算机实际上修复了它,所以请先尝试再做其他事情。或者也许我只是很幸运但值得一试!

回答by userFog

I have my git repo in a directory which is also in the OneDrive folder on my computer. If you use OneDrive on another machine, push from the repo on that computer and then pull/push from your own machine again.

我的 git repo 位于一个目录中,该目录也位于我计算机上的 OneDrive 文件夹中。如果您在另一台机器上使用 OneDrive,请从该计算机上的存储库推送,然后再次从您自己的机器上拉/推送。