I was applying a diff file of an opensource project on the top of my repository using git-am :
git am -3 < /Downloads/refactorWork.diff
but
Moved out of comment to the accepted answer
When you click "Save unified diff" in TortoiseGit, you must right-click the created .diff
or .patch
file and select TortiseGit→Review/apply single patch
instead of Apply Patch Serial...
.
Put the diff file in the root of the folder to which files you want to apply the patch to, first.
I had a patch that looked perfectly fine, including a commit message, Author: header, etc.
I compared the output of git-format-patch, and noticed it used From: headers instead of Author: headers.
Sure enough, if you change Author: to From:, git-am applies the change cleanly.
Use,
git apply -3 patchName.patch
when you encounter conflicts, open your mergtool and resolve conflicts
git mergetool
that's all :)
This diff file is a plain diff, not something generated by git format-patch
. A format-patch
generated diff contains information about the commit author, author date, commit message, ... and maintains this information when creating the commit(s).
Your plain diff does not have these information, so git am
will complain that it is missing naturally.
You should instead have used git apply
which is meant to apply simple patch files like you have in this case which will only apply the patch to the worktree (and index if you tell it to) but does not create any commit automatically.