使用“git am -3”应用补丁时,获取错误消息“致命:sha1 信息缺失或无用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16572024/
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
Get error message ''fatal: sha1 information is lacking or useless" when apply a patch using "git am -3"
提问by michael
I am trying to apply a series of patches from 1 git repository to another git repository using git am -3 "path to a patch". I apply them in order, from patch 1-4, it works fine.
我正在尝试使用 git am -3“补丁路径”将一系列补丁从 1 个 git 存储库应用到另一个 git 存储库。我按顺序应用它们,从补丁 1-4,它工作正常。
But when I come to 5th patch,I get the error saying "fatal: sha1 information is lacking or useless". I go the to git repository where I apply the patch, I do see the file 'dev/afile'. So I wonder why git is complaining about "sha1 information is lacking or useless (dev/afile.c)" and how can I fix my problem?
但是当我来到第 5 个补丁时,我收到错误消息“致命:sha1 信息缺失或无用”。我转到应用补丁的 git 存储库,我确实看到了文件“dev/afile”。所以我想知道为什么 git 会抱怨“sha1 信息缺乏或无用(dev/afile.c)”,我该如何解决我的问题?
$ git am -3 ~/Tmp/mypatches/0005-fifth.patch
Applying: rpmsg: Allow devices to use custom buffer allocator
fatal: sha1 information is lacking or useless (dev/afile.c).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 first patch
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
And why it said "Patch failed at 0001 first patch", when I do "git am -3 ~/Tmp/mypatches/0005-fifth.patch", it completes with no error.
以及为什么它说“补丁在第一个补丁 0001 失败”,当我执行“git am -3 ~/Tmp/mypatches/0005-fifth.patch”时,它没有错误地完成。
Thank you.
谢谢你。
回答by Kornel
The patch file starting with 0001-
cannot be applied cleanly - there is some conflict.
以 开头的补丁文件0001-
不能干净地应用 - 存在一些冲突。
Git wanted to resolve that conflict by looking at commits this patch has been based on, but you don't have those commits in your repository.
Git 希望通过查看此补丁所基于的提交来解决该冲突,但您的存储库中没有这些提交。
Probably the patch has been created from a branch that had commits that were never shared, or either your or submitter's branch has been rebased.
可能补丁是从一个从未共享的提交的分支创建的,或者您或提交者的分支已重新定位。
It doesn't matter that patch 0005-
can be applied with no error. The error is about 0001-
specifically.
0005-
可以无误地应用补丁并不重要。错误是关于0001-
具体的。
回答by Pini Cheyni
Just did the following and was able to solve this issue:
只是做了以下,并能够解决这个问题:
patch -p1 < example.patch
回答by jonasl
Are you using submodules in your project?
你在你的项目中使用子模块吗?
There was a bug in git 1.7.12 to 1.8.1.2 where an updated submodule would cause a rebase (or patch) to fail with the error message:
git 1.7.12 到 1.8.1.2 中存在一个错误,其中更新的子模块会导致 rebase(或补丁)失败并显示错误消息:
fatal: sha1 information is lacking or useless
致命:sha1 信息缺乏或无用
leaving the commit empty if applied.
如果应用,则将提交留空。
More info here.
更多信息在这里。
Updating git to version 1.8.4 solves this problem
将 git 更新到 1.8.4 版本解决了这个问题
回答by Russell Gallop
I had this when trying to apply patches from one repository into one which had unrelated history (the same project but with rebuilt git history). The reason you get the message fatal: sha1 information is lacking or useless (dev/afile.c)
is that when git is trying to do a 3 way merge it needs to access the state of that file. Those files are pointed to by the hashes in the format patch output (e.g.)
我在尝试将一个存储库中的补丁应用到一个历史无关的存储库中时遇到了这个问题(同一个项目,但具有重建的 git 历史记录)。您收到此消息的原因fatal: sha1 information is lacking or useless (dev/afile.c)
是,当 git 尝试进行 3 路合并时,它需要访问该文件的状态。这些文件由格式补丁输出中的哈希值指向(例如)
diff --git a/dev/afile.c b/dev/afile.c
index ebbd50fc0b7..ef1ca87ead0 100644
--- a/dev/afile.c
+++ b/dev/afile.c
ebbd50fc0b7 and ef1ca87ead0 refer to hashes of the content of the files, not commit hashes.
ebbd50fc0b7 和 ef1ca87ead0 指的是文件内容的哈希值,而不是提交哈希值。
If you try:
如果你试试:
git cat-file blob <hash from patch>
Git will report:
Git 会报告:
fatal: Not a valid object name <hash from patch>
Git can't find them because those versions of the file are not available in your local repository (hence the message Repository lacks necessary blobs to fall back on 3-way merge.
). You can make those objects available in your local repository with:
Git 找不到它们,因为这些版本的文件在您的本地存储库中不可用(因此出现消息Repository lacks necessary blobs to fall back on 3-way merge.
)。您可以通过以下方式使这些对象在本地存储库中可用:
git remote add old_repo <url>
git fetch old_repo
Now, when you run:
现在,当你运行时:
git cat-file blob <hash from patch>
You should be given the contents of that file. Now try your git am
command again and it should be able to do 3 way merges.
你应该得到那个文件的内容。现在git am
再次尝试您的命令,它应该能够进行 3 路合并。
回答by Tyler Swartzenburg
I ran into this issue when I tried to create the patch while on the wrong branch.
当我尝试在错误的分支上创建补丁时遇到了这个问题。
I thought "git format-patch ..." would be able to determine what I wanted because you can specify the main branch and the branch you want to patch in the format-patch call. I realized it was wrong because it was mentioning commits that were part of a branch that didn't exist on the site I was patching to.
我认为“git format-patch ...”将能够确定我想要什么,因为您可以在 format-patch 调用中指定主分支和要修补的分支。我意识到这是错误的,因为它提到的提交属于我正在修补的站点上不存在的分支的一部分。
Long story short, make sure you are on the branch you want to patch when you create the patch.
长话短说,确保您在创建补丁时位于要补丁的分支上。