git:补丁没有有效的电子邮件地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17348421/
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
git: Patch does not have a valid e-mail address
提问by tmporaries
I have a patch-file.
我有一个补丁文件。
I want to apply this patch to my code in git repository.
我想将此补丁应用于 git 存储库中的代码。
When I used subversion this process was quite simple: right click -> tortoise svn -> apply patch. It always works as I expected.
当我使用 subversion 时,这个过程非常简单:右键单击 -> tortoise svn -> 应用补丁。它总是按我的预期工作。
But I cannot do this using git. Git doesn't apply my patch. It complains about
但是我不能使用 git 来做到这一点。Git 不应用我的补丁。它抱怨
Patch does not have a valid e-mail address.
补丁没有有效的电子邮件地址。
So, my question is: "How apply patch file in this situation?"
所以,我的问题是:“在这种情况下如何应用补丁文件?”
回答by GoZoner
Git created patches are meant to be applied with Git tools. Use
Git 创建的补丁旨在与 Git 工具一起应用。用
git apply <patch>
If the patch is not created with Git, then just use a patch program 'behind the back' of Git. Often this is the program 'patch':
如果补丁不是用 Git 创建的,那么只需使用 Git 的“背后”补丁程序。通常这是程序“补丁”:
patch <patch>
After applying the patch, add and commit in Git as usual.
应用补丁后,像往常一样在 Git 中添加和提交。
回答by artless noise
This works with mboxfiles downloaded from pipermailused by many open source projects. This probably doesn't work in the OP's case, but the same symptom/question results when using git am
with pipermailextracted messages/patches.
这适用于从许多开源项目使用的pipermail下载的mbox文件。这在 OP 的情况下可能不起作用,但是与pipermail提取的消息/补丁一起使用时会产生相同的症状/问题。git am
Make a backup of the file and edit it to add a line,
备份文件并编辑它以添加一行,
From: [email protected] (Proper Name)
Often the line already exists, but anti-spamfeatures may have converted the @
sign to the text at. You can patch a bunch of files with a gnu sed
command like,
通常情况下,行已经存在,但反垃圾邮件功能可能已经转换的@
标志文本的。您可以使用 gnused
命令修补一堆文件,例如,
sed -ie 's/\(From:.*\) at /@/' *.patch
This just replaces ' at ' with the @
sign. After this, git am
should accept it.
这只是用@
符号替换“ at ” 。在这之后,git am
应该接受它。
If you have access to the git repository you can use the regular commands,
如果您有权访问 git 存储库,则可以使用常规命令,
git checkout oldbranch
git format-patch HEAD~4
This will make four files that are patches of the last changes (change the number for your case).git checkout master
git am *.patch
git checkout oldbranch
git format-patch HEAD~4
这将制作四个文件,它们是最后一次更改的补丁(更改您的案例的编号)。git checkout master
git am *.patch
You get the same commit ids, messages, etc as the remote repository which can be useful later.
您将获得与远程存储库相同的提交 ID、消息等,这在以后会很有用。
Tools like gitkand kdiffdo NOTgenerate the same data as format-patchand you don't get the commit history. If you have this type of data, you must use git apply
or generate patches as above.
像工具gitk和kdiff做不产生相同的数据格式的补丁,你没有得到提交历史。如果您有此类数据,则必须使用git apply
或生成上述补丁。
回答by anon-giraffe
It's possible to have this error if your commit message has a line that begins with From:
. For instance, I had a patch where I fixed a typo, and in the body of the commit message I had:
如果您的提交消息有一行以From:
. 例如,我有一个补丁修复了一个错字,在提交消息的正文中我有:
Fixes a typo.
From: 873524cab1 "Introduced some bug on this commit"
The .patch file, generated by format-patch had two From:
lines, one of which was the email address, and the other was my lousy message. Git am was picking up the second From:
line and trying to find the email address.
format-patch 生成的 .patch 文件有两From:
行,其中一行是电子邮件地址,另一行是我的垃圾邮件。Git am 正在拿起第二From:
行并试图找到电子邮件地址。
The fix was to change the commit message to not have From:
at the beginning of a line.
修复是将提交消息更改为不在From:
行的开头。
回答by Wesley Bland
If it's more helpful for you to use a graphical interface instead of the command line, there are quite a few tools out there that make it relatively simple to do lots of things in Git, including apply patches). The most helpful one that I've found is SourceTree, but I'm sure there's other nice ones out there if you search.
如果使用图形界面而不是命令行对您更有帮助,那么有很多工具可以使在 Git 中执行许多操作(包括应用补丁)变得相对简单)。我发现的最有用的一个是SourceTree,但如果你搜索,我相信还有其他不错的。