您如何描述对文件内容的更改?你可以说第一行“ This is line A”被替换成了“ This is SPARTA”或者甚至把第一行的最后一个单词“ A”换成另一个单词“ SPARTA”。这正是 差异告诉我们的。假设我有这个文件的两个版本,一个叫做 file1.txt,另一个叫做 file2.txt,然后我运行 diff 并得到:
$ diff -u file1.txt file2.txt
--- file1.txt 2011-11-26 11:07:03.131010360 -0500
+++ file2.txt 2011-11-26 11:07:13.171010362 -0500
@@ -1,2 +1,2 @@
-This is line A.
+This is SPARTA.
This is line B, or otherwise #2.
$ cat file1.txt
This is line A.
This is line B, or otherwise #2.
$ cat file2.txt
This is SPARTA.
This is line B, or otherwise #2.
$ diff -u file1.txt file2.txt > changes.patch
$ cat changes.patch
--- file1.txt 2011-11-26 11:09:38.651010370 -0500
+++ file2.txt 2011-11-26 11:07:13.171010362 -0500
@@ -1,2 +1,2 @@
-This is line A.
+This is SPARTA.
This is line B, or otherwise #2.
$ patch < changes.patch
patching file file1.txt
$ cat file1.txt
This is SPARTA.
This is line B, or otherwise #2.
$