[英]Can't apply unified diff patch on Solaris
For example, if I have two files: 例如,如果我有两个文件:
file1: 文件1:
This is file 1
and file2: 和file2:
This is file 2
and create patch with the following command: 并使用以下命令创建补丁:
diff -u file1 file2 > files.patch
result is: 结果是:
--- file1 Fri Aug 13 17:53:28 2010
+++ file2 Fri Aug 13 17:53:38 2010
@@ -1,1 +1,1 @@
-This is file 1
+This is file 2
Then if I try to apply this patch on Solaris with patch command: 然后,如果我尝试在Solaris上使用patch命令应用此补丁:
patch -u -i files.patch
it hangs on: 它挂在:
Looks like a unified context diff.
File to patch:
1. Is there a way to use Solaris native patch command with unified diffs? 1.有没有办法将Solaris 本机补丁命令与统一差异一起使用?
2. Which diff format is considered most portable if it's not possible to apply unified format? 2.如果无法应用统一格式,哪种差异格式被认为是最便携的?
Update: I've found answer on the first part of my question. 更新:我在问题的第一部分找到了答案。 Seems that
patch
on Solaris hangs if the second file (file2 in this case) exists in the same folder as the first one (file1). 如果第二个文件(在本例中为file2)与第一个文件(file1)存在于同一文件夹中,则Solaris上的
patch
似乎挂起。 For example, the following quite common diff: 例如,以下相当常见的差异:
--- a/src/file.src Sat Aug 14 23:07:29 2010
+++ b/src/file.src Sat Aug 14 23:07:37 2010
@@ -1,2 +1,1 @@
-1
-
+2
will not work with quite common patch command: 不适用于相当普通的patch命令:
patch -p1 -u -d a < file.patch
while the following diff ( note second file is renamed ): 而以下差异( 注意重命名第二个文件 ):
--- a/src/file.src Sat Aug 14 23:07:29 2010
+++ b/src/file_new.src Sat Aug 14 23:07:37 2010
@@ -1,2 +1,1 @@
-1
-
+2
will work perfectly. 会很完美。
For the second part of my question see accepted answer below. 对于我的问题的第二部分,请参阅下面接受的答案。
On Solaris /usr/bin/patch
is an old version required to comply with some ancient standards. 在Solaris
/usr/bin/patch
是符合某些古老标准所需的旧版本。 A modern version of GNU patch is provided as /usr/bin/gpatch
on Solaris 8 and later. 在Solaris 8及更高版本中,现有版本的GNU补丁作为
/usr/bin/gpatch
提供。
diff -cr old.new new.txt > patch.txt
gpatch -p0 < patch.txt
Works perfectly for me (using gpatch) 适合我(使用gpatch)
Single Unix v2 and v3 both support context diffs but not unified diffs, so for better portability you should use context diffs ( -c
option to diff
and patch
). 单个Unix v2和v3都支持上下文差异但不支持统一差异,因此为了更好的可移植性,您应该使用上下文差异(
-c
选项来diff
和patch
)。
On older Solaris releases (pre-10, I think), you need to make sure that /usr/xpg4/bin
is before /usr/bin
in your $PATH
, otherwise you may get compatibility versions of some utilities instead of standard ones. 在较旧的Solaris发行版(我认为10之前)中,您需要确保
/usr/xpg4/bin
/usr/bin
位于$PATH
/usr/bin
之前,否则您可能会获得某些实用程序的兼容版本而不是标准实用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.