可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
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?
$ 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.
Thank you.
回答1:
The patch file starting with 0001- cannot be applied cleanly - there is some conflict.
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.
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.
回答2:
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:
fatal: sha1 information is lacking or useless
leaving the commit empty if applied.
More info here.
Updating git to version 1.8.4 solves this problem
回答3:
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.
Long story short, make sure you are on the branch you want to patch when you create the patch.
回答4:
Just did the following and was able to solve this issue:
patch -p1 < example.patch