仅创建修改部分的补丁

Create patch of modified part only

我有一个大约有 1500 行的文件,我只修改了一行并使用了 diff -u original.txt modified.txt > original.patch 而不是只用修改的部分创建一个补丁文件,它不仅有原始的,而且完全在该文件上进行了修改。是否可以只在补丁上修改部分?

如果您删除 -u 选项,它应该可以工作。

diff original.txt modified.txt > original.patch

编辑: 我创建了一个小示例来比较输出:

有以下文件:

==> a.txt <==
one
two
three
four
five

==> b.txt <==
one
two
3
four
five

如果我使用 diff -u a.txt b.txt >> diff-u.p 我会得到以下结果:

==> diff-u.p <==
--- a.txt   2015-09-03 20:16:02.000000000 +0200
+++ b.txt   2015-09-03 20:16:13.000000000 +0200
@@ -1,5 +1,5 @@
 one
 two
-three
+3
 four
 five

请注意,差异包括更改行周围的行,这是使用选项 -u 时的预期结果,来自 diff --help:

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

但是,如果我使用 diff a.txt b.txt >> diff.p,我会得到以下结果:

==> diff.p <==
3c3
< three
---
> 3$

现在 diff 仅包括已更改的行。