oaklodge
oaklodge

Reputation: 748

git apply patch (created with diff -u0) must use --unidiff-zero

I want to apply a patch generated with the "-u0" option of diff.

$ cat file2.txt
123
456
789
$ cat patch1.txt
--- a/file2.txt
+++ b/file2.txt
@@ -2 +2 @@
-456
+ABC
$ git apply -v patch1.txt
Checking patch file2.txt...
error: while searching for:
456

error: patch failed: file2.txt:2
error: file2.txt: patch does not apply

Why the error?

Upvotes: 2

Views: 356

Answers (1)

oaklodge
oaklodge

Reputation: 748

The solution is to use git apply's "--unidiff-zero" option.

$ git apply -v --unidiff-zero patch1.txt
Checking patch file2.txt...
Applied patch file2.txt cleanly.
$ cat file2.txt
123
ABC
789

Hope this helps someone googling around for this problem.

Upvotes: 2

Related Questions