Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 653
tmporaries Avatar asked Jun 27 '13 16:06

tmporaries


People also ask

How do I format a patch in git?

In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.

What is a git patch?

GIT patch or GIT diff is used to share the changes made by you to others without pushing it to main branch of the repository. This way other people can check your changes from the GIT patch file you made and suggest the necessary corrections.

Why is git apply skipping patch?

A patch is usually skipped when the changes it contains were already applied in the past. There are many possible reasons for this: a merge, a cherry-pick, changes operated manually or using another patch etc.


2 Answers

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.

like image 146
GoZoner Avatar answered Sep 17 '22 16:09

GoZoner


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.

like image 29
artless noise Avatar answered Sep 18 '22 16:09

artless noise