6

I have 3 files a\test.txt, b\test.txt and c\test.txt:

a\test.txt :

x
y
z

b\test.txt :

x
z
p
q

c\test.txt :

x
y

Now I created a patch between a and b:

git diff --no-prefix --binary a b > mypatch.patch

Resulting in this patch:

diff --git a/test.txt b/test.txt
index 1b2c8f8..e0b3aec 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
 x
-y
-z
\ No newline at end of file
+z
+p
+q
\ No newline at end of file

Next I want to apply mypatch.patch on c\test.txt:

cd c:\
git apply --ignore-space-change --ignore-whitespace ../mypatch.patch

I get the error:

../mypatch.patch:10: trailing whitespace.
z
../mypatch.patch:11: trailing whitespace.
p
error: patch failed: test.txt:1
error: test.txt: patch does not apply

I have read a bunch of post here on SO but have still not managed to get it applied any ideas?

I don't see any trailing spaces in mypatch.patch

u123
  • 15,603
  • 58
  • 186
  • 303

2 Answers2

3

The fact that the patch does not apply is not related to the trailing whitespace.

The patch tries to remove the y and z lines, but z does not exist in the file you're trying to apply it to (c/text.txt).

Something like the following would apply :

diff --git a/test.txt b/test.txt
index 66455a1..1a0d96d 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,4 @@
 x
-y
\ No newline at end of file
+z
+p
+q
\ No newline at end of file
Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
0

Please try patch -p1 < filename.patch.

BTW, a similar question here: My diff contains trailing whitespace - how to get rid of it?

KikiYu
  • 3,087
  • 1
  • 13
  • 14