Hi
After you read this article, you’ll be able to apply patch files/diffs and deal with possible errors in the process.
Let’s assume the patch is in the file fix-bug.patch (the extension doesn’t matter). The directory software-1.0 contains the files to patch. Applying a patch file/diff then works like this:
- Make a backup. On Linux you can use the command:
markus@ubuntu:~$ cp -a software-1.0 software-1.0.before-patch - Run patch (for Windows: patch.exe) like this:
markus@ubuntu:~$ patch -Np1 -d software-1.0 < fix-bug.patch
Attention: this is patch minus N p digit one …, not minus N p small letter L!
If the result looks something like this:
markus@ubuntu:~$ patch -Np1 -d software-1.0 < fix-bug.patch patching file bar.h patching file quux.c patching file foo.txt markus@ubuntu:~$
then it worked and the patch file applied cleanly.
If you got different messages, they may be just warnings or they may be error messages. In any case the patch may have been applied incorrectly or only partially. To be safe, let’s restore from the backup first. Then we’ll figure out what the warning or error messages mean. To restore for Linux:
markus@ubuntu:~$ rm -rf software-1.0 markus@ubuntu:~$ cp -a software-1.0.before-patch software-1.0
Error messages and how to handle them
And now, here’s a list of messages that may appear. Each message links to a paragraph about what to do when this message appears.
-
can't find file to patch at input line nnn. File to patch:
-
No file to patch. Skipping patch. n out of n hunks ignored.
-
Hunk #n FAILED at nnn. n out of n hunks FAILED -- saving rejects to file file.rej
-
Hunk #n succeeded at nnn (offset n lines).
-
Hunk #n succeeded at nnn with fuzz n.
-
malformed patch at line nnn
it helped me greatly thanks a lot , very well informative article