无法在 Solaris 上应用统一差异补丁
例如,如果我有两个文件:
file1:
This is file 1
和 file2:
This is file 2
并使用以下命令创建补丁:
diff -u file1 file2 > files.patch
结果是:
--- 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
然后,如果我尝试使用 patch 命令在 Solaris 上应用此补丁:
patch -u -i files.patch
它会挂起:
Looks like a unified context diff.
File to patch:
1。有没有办法使用带有统一差异的 Solaris 本机补丁命令?
2.如果无法应用统一格式,哪种差异格式被认为是最可移植的?
更新: 我已经找到了问题第一部分的答案。如果第二个文件(本例中为 file2)与第一个文件(file1)位于同一文件夹中,Solaris 上的 patch
似乎会挂起。例如,以下非常常见的 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
无法与非常常见的 patch 命令一起使用:
patch -p1 -u -d a < file.patch
而以下 diff (注意第二个文件已重命名):
--- 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
将完美工作。
对于我的问题的第二部分,请参阅下面接受的答案。
For example, if I have two files:
file1:
This is file 1
and 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:
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?
2. Which diff format is considered most portable if it's not possible to apply unified format?
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). 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 -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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Solaris 上,
/usr/bin/patch
是一个旧版本,需要遵守一些古老的标准。在 Solaris 8 及更高版本上,现代版本的 GNU 补丁以
/usr/bin/gpatch
形式提供。On Solaris
/usr/bin/patch
is an old version required to comply with some ancient standards.A modern version of GNU patch is provided as
/usr/bin/gpatch
on Solaris 8 and later.非常适合我(使用 gpatch)
Works perfectly for me (using gpatch)
单一 Unix v2 和 v3 都支持上下文差异,但不支持统一差异,因此为了更好的可移植性,您应该使用上下文差异(
-c
选项为diff
和patch)。
在较旧的 Solaris 版本(我认为是 10 之前的版本)上,您需要确保
中的
,否则您可能会获得某些实用程序的兼容版本而不是标准版本。/usr/xpg4/bin
位于/usr/bin
之前$PATHSingle Unix v2 and v3 both support context diffs but not unified diffs, so for better portability you should use context diffs (
-c
option todiff
andpatch
).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.