简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM