如何让diff看起来像svn diff?

19

我很蠢也不会用Google。如果有必要的话(在OS X上),你怎样才能让diff看起来像svn的diff?即使我看了手册页也没搞懂 :(

我的要求是:

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.

2
我不得不查一下谷歌,+1!! - gonzobrains
3个回答

28
你需要使用 -u 标志。
diff -u file1 file2

来自 diff 手册:

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

它并不是完全相同(例如没有一大排等号),但它应该能够满足你的需要。你从上述示例中提取的代码:

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

6

Subversion使用稍微扩展的统一差异格式。维基百科关于Diff的页面解释了该格式本身,并指出了与subversion的差异。

正如已经提到的,差异工具(详见其man页面)使用-u选项生成统一差异。


5
diff -u file1 file2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接