should convert a .diff
file to .patch
file, how to?
No, the extension isn't important. The content is.
You can try, and if doesn't work, fallback on this comment by Евгений Чорба (Evgeny Solis):
For those who has no patch command and git apply
does nothing. The solution is:
Let's modify the patch file!
From
diff --git a/uc_attribute/uc_attribute.admin.inc b/uc_attribute/uc_attribute.admin.inc
index b9a978a..ef33ca3 100644
--- a/uc_attribute/uc_attribute.admin.inc
+++ b/uc_attribute/uc_attribute.admin.inc
To:
diff --git ubercart/uc_attribute/uc_attribute.admin.inc ubercart/uc_attribute/uc_attribute.admin.inc
index 1c35bf8..587fa67 100755
--- ubercart/uc_attribute/uc_attribute.admin.inc
+++ ubercart/uc_attribute/uc_attribute.admin.inc
Apply patch from project root using
git apply -p0 PATCHFILE.patch
Verbose:
You should replace 'a/
' and 'b/
' from patchfile with '<projectname>/
' (In my example it is 'ubercart
')
After applying patch you may see warning like
warning: ubercart/uc_attribute/uc_attribute.admin.inc has type 100755, expected 100644
It's OK, don't worry.
NOTE! If patch contains diffs for a several files you should replace ALL occurrences of 'a/<anypath>
' and 'b/<anypath>
'
Note: the OP chengpei has seen the other error message when using git apply
:
got a error: fatal: corrupt patch at line 7
It is documented in "“fatal: corrupt patch at line XX
” when staging single line"
having newlines at the end of the file fixes it, and removing them causes it.
Magnus Bäck recommends in the comments:
Instead of editing the patch file to remove directory prefixes a/
and b/
, run patch -p1
to have the first directory component stripped automatically.
tremby adds in the comments:
To produce a diff from git without the a/
and b/
prefixes you can use --no-prefix
as an option to git diff