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
Hover the mouse on warning in VS Code or any IDE and use quick fix to remove white spaces. Press f1 then type trim trailing whitespace .
You can prefix - to disable any of them (e.g. -trailing-space ): ### blank-at-eol treats trailing whitespaces at the end of the line as an error (enabled by default).
Troubleshoot Git Patch Error: file already exists in index You are attempting to apply a patch containing files already present in your branch. Double-check the files present in your index. Use the git ls-files command and add the --stage option.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With