Jul 30, 2009

Linux Patch 用法

From Wikipedia


To create a patch, one could run the following command in a shell:
$ diff -u oldFile newFile > mods.diff  # -u tells diff to output unified diff format
To apply a patch, one could run the following command in a shell:
$ patch < mods.diff
This tells patch to apply the changes to the specified files described in mods.diff. Patches to files in subdirectories require the additional -pnumber option, where number is 1 if the base directory of the source tree is included in the diff, and 0 otherwise.
Patches can be undone, or reversed, with the '-R' option:
$ patch -R < mods.diff
If the file is not identical to the version the diff was generated against, the patch will not be able to be applied cleanly. For example, if lines of text are inserted at the beginning, the line numbers referred to in the patch will be incorrect. patch is able to recover from this, by looking at nearby lines to relocate the text to be patched. It will also recover when lines of context (for context and unified diffs) are altered; this is described as fuzz.

0 comments: