You don't need patch
for this; it's for extracting changes and sending them on without the unchanged part of the file.
The tool for merging two versions of a file is merge
, but as @vonbrand
wrote, you need the "base" file from which your two versions diverged. To do a merge without it, use diff
like this:
diff -DVERSION1 file1.xml file2.xml > merged.xml
It will enclose each set of changes in C-style #ifdef
/#ifndef
"preprocessor" commands, like this:
#ifdef VERSION1
<stuff added to file1.xml>
#endif
...
#ifndef VERSION1
<stuff added to file2.xml>
#endif
If a line or region differs between the two files, you'll get a "conflict", which looks like this:
#ifndef VERSION1
<version 1>
#else /* VERSION1 */
<version 2>
#endif /* VERSION1 */
So save the output in a file, and open it in an editor. Search for any places where #else
comes up, and resolve them manually. Then save the file and run it through grep -v
to get rid of the remaining #if(n)def
and #endif
lines:
grep -v '^#if' merged.xml | grep -v '^#endif' > clean.xml
In the future, save the original version of the file. merge
can give you much better results with the help of the extra information. (But be careful: merge
edits one of the files in-place, unless you use -p
. Read the manual).
It's a patch that undoes the earlier patch. It can be made with patch -R -pX bad.patch
(where X is the number of directory levels to strip from the patch and bad.patch is the patch we want to undo) followed by a git commit
A "reversed patch" is when someone accidentally makes a patch with diff -u foo.c foo.c.orig
(where foo.c is the newer file) instead of the correct diff -u foo.c.orig foo.c
The "reversed or previous applied patch" error indicates the patch has already been applied. I can not be more specific without knowing the contents of your kernelsuspend.patch
file.
If you have the .git directory for the kernel source, you can look at the log for a single file with the git log
command followed by the file name. e.g. git log fs/eventpoll.c
or even git log -p fs/eventpoll.c
.
Best Answer
If the patch only contains changes to a single file, you should be able to tell
patch
to apply those changes to a file of your choice by specifying it before the patch name:will apply
withthis.patch
tomyfile
, ignoring the file name in the patch.Quoting the man page: