patch: Only garbage was found in the patch input

ε祈祈猫儿з 提交于 2019-11-30 11:37:32

Generate the diff using "diff -ruN path1 path2", apply the patch using "patch -p{N} < patchfile", where N determines the prefix of the path to strip from the files in the diff. Just look at the patch & analyze the "diff" lines to see what should be stripped off. (See: man patch) . Before applying the patch, do use "patch --dry-run -p0 < patchfile" to make sure everything will be at least reasonably sane.

Edit: Note the different contents of a patch generated using normal diff, unified diff (-u) and context diff (-c), and you'll see that the filename simply isn't included in 'normal' diff. The "diff" command is there, but the filename to patch is not. (Note also that the actual 'diff' output varies a bit from platform to platform, program to program, and patch has to do a little bit of interpolation to determine the patch format, and even tries to guess if you've given it the wrong options).

$ diff -r -u a b
diff -r -u a/dir/file1 b/dir/file1
--- a/dir/file1 2012-08-02 18:27:30.050247358 -0700
+++ b/dir/file1 2012-08-02 18:27:27.190198620 -0700
@@ -1 +1 @@
-contents A
+contents B

$ diff -r -c a b
diff -r -c a/dir/file1 b/dir/file1
*** a/dir/file1 2012-08-02 18:27:30.050247358 -0700
--- b/dir/file1 2012-08-02 18:27:27.190198620 -0700
***************
*** 1 ****
! contents A
--- 1 ----
! contents B

$ diff -r  a b
diff -r a/dir/file1 b/dir/file1
1c1
< contents A
---
> contents B

I had this problem when doing:

patch <file_patch> <file_destination>

instead of:

patch <file_destination> <file_patch>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!