如何应用.diff文件 [英] How to apply a .diff file

查看:948
本文介绍了如何应用.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 = {}



我应该手动修改我的本地User.lua,还是可以像应用修补程序文件一样应用diff文件? (或者将.diff文件转换为.patch文件,如何操作?)

感谢您的帮助。

应该将一个 .diff 文件转换为 .patch / code>文件,如何?

不,扩展并不重要。 您可以尝试,如果不起作用,则可以使用ЕвгенийЧорба(Evgeny Solis)


对于那些没有补丁命令和 git apply 什么也不做。解决方案是:

让我们修改补丁文件!






  diff --git a / uc_attribute / uc_attribute.admin.inc b / uc_attribute / uc_attribute.admin.inc 
索引b9a978a..ef33ca3 100644
--- a / uc_attribute / uc_attribute.admin.inc
+++ b / uc_attribute / uc_attribute.admin.inc




收件人:



  diff --git ubercart / uc_attribute / uc_attribute.admin.inc ubercart / uc_attribute / uc_attribute.admin.inc 
索引1c35bf8..587fa67 100755
--- ubercart / uc_attribute / uc_attribute.admin.inc
+++ ubercart / uc_attribute / uc_attribute.admin.inc




应用从项目根目录下使用

修补程序

git apply -p0 PATCHFILE.patch



详细信息:

你应该用patchfile替换' a / '和' b / ',其中'< ;项目名称> / '(在我的例子中,它是' ubercart ')






 警告:ubercart / uc_attribute / uc_attribute.admin.inc的类型为100755,预计为100644 




没关系,别担心。

注意!如果patch包含多个文件的差异,则应替换所有出现的' a /< anypath> '和' b /< anypath> '







注意: OP chengpei has git apply



<$时看到另一个错误消息
p $ p> 出现错误:致命:在第7行损坏的补丁

它在记录在致命:XX行损坏修补程序时登台行


在文件末尾有换行符修复它,删除它们会导致它。







MagnusBäck 建议在评论中
$ b


不用编辑补丁文件来删除目录前缀 a / b / ,运行 patch -p1 以自动剥离第一个目录组件。


tremby 增加在评论中:


如果不使用 a / b / 来从git生成diff,前缀你可以使用 - no-prefix 作为 git diff



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.

解决方案

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

这篇关于如何应用.diff文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆