I have a file with 1500 lines, more or less and I modified only one line and used diff -u original.txt modified.txt > original.patch
and instead of creating a patch file with the modified part only, it has not only the original, but the modified entirely on that file. Is it possible to have ONLY the modified part on the patch?
Asked
Active
Viewed 83 times
1

7VoltCrayon
- 662
- 1
- 7
- 22

Secafo
- 107
- 6
1 Answers
1
It should work if you remove the -u
option.
diff original.txt modified.txt > original.patch
Edit: I created a small example to compare the outputs:
Having the following files:
==> a.txt <==
one
two
three
four
five
==> b.txt <==
one
two
3
four
five
If I use diff -u a.txt b.txt >> diff-u.p
I get the following:
==> 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
Note that diff included the lines surrounding the changed line, this is to be expected when using the option -u
, from diff --help
:
-u -U NUM --unified[=NUM] Output NUM (default 3) lines of unified context.
However, if I use diff a.txt b.txt >> diff.p
I get the following:
==> diff.p <==
3c3
< three
---
> 3$
Now diff only includes the lines that have changed.

Clauds
- 950
- 11
- 24
-
But I needed with the diff, because I'm using git to apply the patch and I don't know how to apply that patch to a file without having the diff on it. – Secafo Sep 01 '15 at 20:23
-
Not sure if I understand... You would still do the diff but you would do the diff without the option -u. How does your output look like if you do that? – Clauds Sep 02 '15 at 06:07
-
Without -u it's something with > and < and with the -u I have the diff with ---, @@, the position of the changes and so on. – Secafo Sep 02 '15 at 14:30
-
Have a look at the example I included in my answer. Is that not what you were asking for? – Clauds Sep 03 '15 at 18:29