git commit 停止工作 - 构建树时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14448326/
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-10 15:18:57  来源:igfitidea点击:

git commit stopped working - Error building trees

git

提问by gorn

I can not commit a change:

我无法提交更改:

$ git commit
error: invalid object 100644 13da9eeff5a9150cf2135aaed4d2e337f97b8114 for 'spec/routing/splits_routing_spec.rb'
error: Error building trees

I tried so far:

我到目前为止尝试过:

$ git fsck | grep 13da
missing blob 13da9eeff5a9150cf2135aaed4d2e337f97b8114

and also:

并且:

$ git prune
error: Could not read 1394dce6fd1ad15a70b2f2623509082007dc5b6c
fatal: bad tree object 1394dce6fd1ad15a70b2f2623509082007dc5b6c

and also:

并且:

$ git fsck | grep 13da
missing blob 13da9eeff5a9150cf2135aaed4d2e337f97b8114

but nothing helped. Should I delete the file, commit and reintroduce back? I am willing to lose little bit of history if it brings git commit back.

但没有任何帮助。我应该删除文件,提交并重新引入吗?如果它把 git commit 带回来,我愿意失去一点点历史。

采纳答案by LopSae

You might have a corrupted object in your git repository.

您的 git 存储库中可能有损坏的对象。

If you have a remote, or other clones of this repository, you could grab from there the problematic file and just replace it on your local repo.

如果您有此存储库的远程或其他克隆,您可以从那里获取有问题的文件,然后将其替换到您的本地存储库中。

The file you want would be in:

你想要的文件将在:

/repo/.git/objects/13/da9eeff5a9150cf2135aaed4d2e337f97b8114

回答by Alex Nikulin

This error means that you have a file with hash 13da9eeff5a9150cf2135aaed4d2e337f97b8114, and this hash is not present in .git/objects/../, or it's empty. When this error occurred, I only had this hash in the error, without the file path. Then I tried to do git gc --autoand git reset --hard. After one of these commands (these commands did not fix my problem), I got the path of the file that triggers the error.

这个错误意味着你有一个带有 hash 的文件13da9eeff5a9150cf2135aaed4d2e337f97b8114,而这个 hash 不存在于 中.git/objects/../,或者它是空的。当这个错误发生时,我在错误中只有这个哈希值,没有文件路径。然后我尝试做git gc --autogit reset --hard。在这些命令之一(这些命令没有解决我的问题)之后,我得到了触发错误的文件的路径。

You just need to generate the object hash:

您只需要生成对象哈希:

git hash-object -w spec/routing/splits_routing_spec.rb

For more information see documentation. In the documentation, there is an additional way of repairing this error.

有关更多信息,请参阅文档。在文档中,还有一种修复此错误的其他方法。

P.S. This was the only way that was helpful for me.

PS 这是唯一对我有帮助的方法。

回答by Tom Macdonald

git reset --hardshould bring your repository back to normal, but you will lose uncommitted changes.

git reset --hard应该使您的存储库恢复正常,但您将丢失未提交的更改。

回答by Archias

If the problematic file is being added by your change you can just remove it from the index and add it again:

如果您的更改添加了有问题的文件,您只需将其从索引中删除并再次添加:

git reset <file> 
git add <file>

回答by latvian

For me it was just permissions issue. When I run with 'sudo', it worked. perhaps something to do with mac environmnet

对我来说,这只是权限问题。当我使用“sudo”运行时,它起作用了。也许与mac环境有关

回答by YiDing

This can be caused by some third-party synchronization APP such as Dropbox and Jianguoyun. There might be two ways based on my experience:

这可能是由一些第三方同步 APP 如 Dropbox 和建国云引起的。根据我的经验,可能有两种方法:

  1. You can try to undo recent synchronization operations.
  2. Remove the related files from the folder, commit, and then move back the files.
  1. 您可以尝试撤消最近的同步操作。
  2. 从文件夹中删除相关文件,提交,然后将文件移回。

回答by Sathibabu P

In my case, I solved it by:

就我而言,我通过以下方式解决了它:

git reset --mixed

git reset --mixed

回答by Abd Rmdn

Easy work around solution, if you're not really concerned on the track of the file, you can duplicate the file and remove the original, commit first the deletion and addition, then rename to original again.

简单的解决方案,如果你不是很关心文件的轨迹,你可以复制文件并删除原始文件,首先提交删除和添加,然后再次重命名为原始文件。

Git should build back again normally

Git 应该正常重新构建

回答by Jughead

In my case, this was due to a different version of git. I had been using my repository through the official Windows port of git and started using the MinGW port with the same version number.

就我而言,这是由于 git 版本不同。我一直通过 git 的官方 Windows 端口使用我的存储库,并开始使用具有相同版本号的 MinGW 端口。

I started to encounter this issue when trying to commit with MinGW git. Switching back to windows Git solved the issue.

我在尝试使用 MinGW git 提交时开始遇到这个问题。切换回 Windows Git 解决了这个问题。

回答by Yang-Hsing Lin

In my case, it is the file in remote branch that is broken. I solved it by:

就我而言,是远程分支中的文件损坏了。我通过以下方式解决了它:

  1. remove the remote branches at all by $ git remote rm origin
  2. add the remote back again: $ git remote add origin <the-remote-url>
  3. fetch the remote again: $ git fetch origin
  4. reset-hard to the desired branch on origin (say, develop): $ git reset --hard origin/develop
  1. 完全删除远程分支 $ git remote rm origin
  2. 再次添加遥控器: $ git remote add origin <the-remote-url>
  3. 再次获取遥控器: $ git fetch origin
  4. reset-hard 到原点所需的分支(例如,develop):$ git reset --hard origin/develop

Then everything goes back to normal.

然后一切恢复正常。