tags:

views:

322

answers:

3

I'm bad dumb and having no google fu. How do you get diff (on os x if it matters...) to look like svn diffs? Couldn't figure it out from the man page either. :(

What I want

Index: test.txt
===================================================================
--- test.txt (revision 365)
+++ test.txt (working copy)
@@ -1,7 +1,9 @@
 This
 is
 the
-original
+updated
+and
+awesomer
 file.

-Unf.
+Duh.
+1  A: 
diff -u file1 file2
Harold L
+6  A: 

You want the -u flag.

diff -u file1 file2

From the diff man page:

   -u  -U NUM  --unified[=NUM]
          Output NUM (default 3) lines of unified context.

It's not exactly the same (no big row of equals signs, for example), but it should do what you want. Your example from above:

--- file1   2009-10-16 15:14:24.000000000 -0700
+++ file2   2009-10-16 15:14:50.000000000 -0700
@@ -1,7 +1,9 @@
 This
 is
 the
-original
+updated
+and
+awesomer
 file.

-Unf.
+Duh.
Carl Norum
+2  A: 

subversion uses a slightly extended version of the unified diff format. Wikipedias page on Diff explains the format itself, and also notes the differences to the subversion ones.

As has been said, the diff tool (see its man page for details) uses the -u option to produce unified diffs.

bluebrother