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?"
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.
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.
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.
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.
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,
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With