Transferred from: http://blog.csdn.net/dl0914791011/article/details/17299103
Patches are generated by the Diff tool, and patch tools are patched.
Before using diff, you need to keep an unmodified source code and then modify a copy of the source code elsewhere. Diff compares these two copies of source code to generate patches. The modified source code must retain the original file name, for example, if you modify the source of the A.C file, then, the modified file is also named A.C, you can copy A.C before the change to A.ORIG.C for backup.
1. Generate patches for individual files
1 $ diff-up linux-2.6. 28.8/net/sunrpc/svc.orig.c linux-2.6. 28.8/net/sunrpc/svc.c > patch
This command produces output similar to the following, which you redirect to a file, which is a patch.
1Diff-up linux-2.6.28.8/net/sunrpc/svc.orig.c the-Geneva- - ,: -:04.000000000+08002+ + linux-2.6.28.8/net/sunrpc/svc.c the-Geneva- - +: -:41.859375000+08003@@ -1050, One+1050, One@@ Svc_process (structSvc_rqst *RQSTP)
Parameter description:-U Displays the front and back lines (context) of the difference row, with the default being 3 rows before and after, so that there is more information in the patch.-P Displays information about the C function where the code is located. 2. Generate patches for multiple files
1 $ diff-uprn linux-2.6. 28.8. orig/net/sunrpc/linux-2.6. 28.8/net/sunrpc/> patch
This command compares all the source differences in the two directories of linux-2.6.28.8.orig/net/sunrpc/and linux-2.6.28.8/net/sunrpc/. Parameter detail:-R compares a directory and all its subdirectories (that is, the entire directory tree) recursively .-N If a file is missing, compare it as an empty file. If you do not use this option, when diff discovers old code or the new code is missing a file, simply prompt for missing files. If you use this option, the newly added file will be printed out as a new part. 3. Patch-generated patches,The path information contains the name of your Linux source root directory, but other people's source root directory may be other names, so, when patching, to enter your Linux source root directory, and tell the patch tool, please ignore the patch in the first level of directory of the path(parameter-p1).
1 $ patch-p1 < Patch1.diff
The diff command must be performed in the top level directory of the root directory of the entire Linux source code.4. Example creates a patch for the modified kernel and then patches the unmodified kernel with the resulting patch, with the directory linux-2.6.31.3 as the unmodified kernel and the directory Linux-2.6.31.3_1 as the modified kernel
1 $ diff-uparn linux-2.6. 31.3 linux-2.6. 3_1/> mypatch2 $ cd linux-2.6. 31.3 3 $ patch-p1 < Mypatch
Note the point :
1. When you hit patch, the parameter-P1 is 1 instead of L. Why ignore the first level directory, because the project under the same tree structure, but the project name may not be the same, so when the patch can be P1 to avoid this problem. This can be done by looking at the patch content to determine the path to the specific patch.
2.
Patch and patch generation under Linux