Question

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.

Was it helpful?

Solution

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).

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.

OTHER TIPS

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.

diff -cr old.new new.txt > patch.txt

gpatch -p0 < patch.txt

Works perfectly for me (using gpatch)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top