Generate patch and patch in Linux

Source: Internet
Author: User
The patch is generated using the diff tool, and the patch tool is patched.

Before using diff, you need to keep a copy of the unmodified source code and modify the source code elsewhere. diff compares the two source codes to generate a patch. the modified source code must retain the original file name. For example, if you modify. c file. The modified file is still named. c. You can copy. C is. orig. c. Back up data.

1. Generate patches for a single file

$ Diff-Up Linux-2.6.28.8/Net/SunRPC/SVC. orig. c Linux-2.6.28.8/Net/SunRPC/SVC. c

This command will generate output similar to the following. You can redirect it to a file, which is a patch.

Diff - Up Linux - 2 . 6 . 28 . 8 / Net / SunRPC / SVC. orig. c 2009 - 03 - 17 08 : 50 : 04 . 000000000 + 0800
+ + + Linux - 2 . 6 . 28 . 8 / Net / SunRPC / SVC. c 2009 - 03 - 30 19 : 18 : 41 . 859375000 + 0800
@@ - 1050 , 11 + 1050 ,11 @ Svc_process ( Struct Svc_rqst * Rqstp)Parameter description:-u displays the rows (context) before and after the different rows. By default, three rows are displayed before and after the difference, so that more information is displayed in the patch.-P Code Information about the C function. 2. Generate patches for multiple files $ Diff-Uprn Linux-2.6.28.8. Orig/Net/SunRPC/Linux-2.6.28.8/Net/SunRPC/

This command compares all source code differences under the linux-2.6.28.8.orig/NET/SunRPC/and linux-2.6.28.8/NET/SunRPC/directories.

Parameter description:-r recursively compares a directory with all its subdirectories (that is, the entire directory tree ). -N if a file is missing, it is treated as an empty file for comparison. if this option is not used, when diff finds that the old Code or the new Code lacks a file, it simply prompts that the file is missing. if this option is used, the newly added file is printed out as a newly added part. 3. in the patch generated by patching, the path information contains the name of your Linux source code root directory, but other people's source code root directory may be another name. Therefore, when patching, to enter the root directory of your Linux source code and tell the patch tool, ignore the first directory (parameter-P1) of the path in the patch ). $ Patch-P1<Patch1.diff

The diff command must be executed in the upper-level directory of the root directory of the entire Linux source code. 4. The example generates a patch for the modified kernel, and then patches the unmodified kernel with the generated patch, the directory linux-2.6.31.3 is the unmodified kernel, the directory linux-2.6.31.3_1 is the modified Kernel$ Diff-Uparn Linux-2.6.31.3Linux-2.6.31.3_1/ >Mypatch
$ CD Linux-2.6.31.3
$ Patch-P1<Mypatch

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.