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

4

14

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?"

Involve answered 27/6, 2013 at 16:26 Comment(0)
M
9

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.

Machute answered 27/6, 2013 at 17:9 Comment(4)
Exactly this command doesn't work. I wrote above that git complains about missed email.Involve
Did you create the patch with Git?Machute
No. This is a "unified" patch format generated by tortoise diff viewer.Involve
See updated answer; apply the patch 'behind the back' of Git.Machute
S
6

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: [email protected] (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.

Sufflate answered 1/10, 2013 at 21:36 Comment(3)
After adding email address in the .patch file, git whines about lacking SHA hash. I guess I will try GoZoner's answer.Jesicajeske
I have my local repo, into which some source code was copied a year ago from foreign project. Meanwhile that project was updated, as well as my local repo. I want to incorporate foreign improvements. I made a patch of changes made to foreign project by copying latest version into old branch and showing all the differences. I still haven't found a tool which will apply this unified diff to my local repo.Jesicajeske
I finally did it with kdiff3, but not using the patch which I have previously created.Jesicajeske
S
1

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.

Snuffbox answered 27/6, 2013 at 18:28 Comment(0)
T
1

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.

Testa answered 27/7, 2015 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.