git: Patch does not have a valid e-mail address

本小妞迷上赌 提交于 2019-12-08 14:58:10

问题


I have a patch-file.

I want to apply this patch to my code in git repository.

When I used subversion this process was quite simple: right click -> tortoise svn -> apply patch. It always works as I expected.

But I cannot do this using git. Git doesn't apply my patch. It complains about

Patch does not have a valid e-mail address.

So, my question is: "How apply patch file in this situation?"


回答1:


Git created patches are meant to be applied with Git tools. Use

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':

patch <patch>

After applying the patch, add and commit in Git as usual.




回答2:


This works with mbox files downloaded from pipermail used 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 pipermail extracted messages/patches.


Make a backup of the file and edit it to add a line,

From: name@domain.com (Proper Name)

Often the line already exists, but anti-spam features may have converted the @ sign to the text at. You can patch a bunch of files with a gnu sed command like,

sed -ie 's/\(From:.*\) at /\1@/' *.patch

This just replaces ' at ' with the @ sign. After this, git am should accept it.


If you have access to the git repository you can use the regular commands,

  1. git checkout oldbranch
  2. git format-patch HEAD~4 This will make four files that are patches of the last changes (change the number for your case).
  3. git checkout master
  4. git am *.patch

You get the same commit ids, messages, etc as the remote repository which can be useful later.


Tools like gitk and kdiff do NOT generate the same data as format-patch and you don't get the commit history. If you have this type of data, you must use git apply or generate patches as above.

See: Difference between git format-patch and git diff.




回答3:


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.




回答4:


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:

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.

The fix was to change the commit message to not have From: at the beginning of a line.



来源:https://stackoverflow.com/questions/17348421/git-patch-does-not-have-a-valid-e-mail-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!