How to apply a .diff file

孤街浪徒 提交于 2019-12-06 00:32:30

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/21274840/how-to-apply-a-diff-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!