简体   繁体   English

如何应用.diff文件

[英]How to apply a .diff file

I got a .diff type file , seems like blew: 我有一个.diff类型的文件,好像吹了:

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 ? 我应该手动修改我的本地User.lua,还是可以像应用补丁文件一样应用diff文件? (or should convert a .diff file to .patch file, how to?) (或者应该将.diff文件转换为.patch文件,如何?)

would be thankful for any help. 会感激任何帮助。

should convert a .diff file to .patch file, how to? 应该将.diff文件转换为.patch文件,如何?

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. 对于没有补丁命令的人, git apply什么都不做。 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 git apply -p0 PATCHFILE.patch

Verbose: 详细:
You should replace ' a/ ' and ' b/ ' from patchfile with ' <projectname>/ ' (In my example it is ' ubercart ') 你应该用' <projectname>/ '替换patchfile中的' a/ '和' b/ <projectname>/ '(在我的例子中它是' 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> ' 如果patch包含多个文件的差异,则应替换所有出现的' a/<anypath> '和' b/<anypath> '


Note: the OP chengpei has seen the other error message when using git apply : 注意: OP chengpei在使用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 " 它被记录在“ fatal: corrupt patch at line XX ”,当分段单行时

having newlines at the end of the file fixes it, and removing them causes it. 在文件末尾有换行符修复它,并删除它会导致它。


Magnus Bäck recommends in the comments : MagnusBäck 在评论中建议:

Instead of editing the patch file to remove directory prefixes a/ and b/ , run patch -p1 to have the first directory component stripped automatically. 不是编辑补丁文件以删除目录前缀a/b/ ,而是运行patch -p1以自动剥离第一个目录组件。

tremby adds in the comments : tremby 在评论中添加:

To produce a diff from git without the a/ and b/ prefixes you can use --no-prefix as an option to git diff 要从没有a/b/前缀的git生成diff,可以使用--no-prefix作为git diff的选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM