10

I got a .diff type file , seems like blew:

diff --git a/res/User.lua b/res/User.lua
index db8c2cc..4d2af0f 100644
--- a/res/User.lua
+++ b/res/User.lua
@@ -5,6 +5,7 @@ resetPassword = {}
+UserInfo = {}

Should i manually modify my local User.lua , or can i apply a diff file as like apply a patch file ? (or should convert a .diff file to .patch file, how to?)

would be thankful for any help.

Magnus Bäck
  • 11,381
  • 3
  • 47
  • 59
codeplay
  • 620
  • 1
  • 6
  • 19

1 Answers1

8

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks, have tried git apply -p0 PATCHFILE.patch (Acturaly, i tried before,), Unfortunately, got a error: fatal: corrupt patch at line 7... – codeplay Jan 22 '14 at 08:30
  • @chengpei did you replace the `a/` and `b/` as mentioned in the answer? and did you apply it from the root folder of your repo? – VonC Jan 22 '14 at 09:12
  • i have fixed the " got a error: fatal: corrupt patch at line 7" issue,here is the answer http://stackoverflow.com/a/12548088/1731438 – codeplay Jan 22 '14 at 10:28
  • @chengpei Great! I have included your conclusion, as well as a link to the other answer, in my answer for more visibility. – VonC Jan 22 '14 at 11:14
  • 1
    Instead of editing the patch file to remove directory prefixes a/ and b/, run `patch -p1` to have the first directory component stripped automatically. – Magnus Bäck Jan 22 '14 at 14:17
  • @MagnusBäck good point. I have included it in the answer for more visibility. – VonC Jan 22 '14 at 14:21
  • To produce a diff from git without the `a/` and `b/` prefixes you can use `--no-prefix` as an option to `git diff`. – tremby Nov 16 '15 at 21:51
  • @MagnusBäck Where and when do you use `patch -p1`? What would the full command look like? – 1.21 gigawatts Feb 04 '21 at 07:52
  • @1.21gigawatts To apply a patch created with `git diff` instead of `git diff --no-prefix`: see https://gist.github.com/zeuxisoo/980174 and https://medium.com/odds-team/create-a-patch-file-from-git-diff-c746be60d1e – VonC Feb 04 '21 at 07:56