patch: Only garbage was found in the patch input
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>