Generation and use of patch files

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.

The diff command must be executed in the upper-level directory of the root directory of the entire Linux source code.

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.

--- Linux-2.6.28.8/NET/SunRPC/svc. orig. c 08:50:04. 000000000 + 0800

++ Linux-2.6.28.8/NET/SunRPC/svc. c 19:18:41. 859375000 + 0800

@-1050,11 + 1050,11 @ svc_process (struct svc_rqst * rqstp)

Parameters:

-U displays the rows (context) before and after the different rows. The default value is three rows before and after the difference. In this way, the patch contains more information.

-P: displays information about the C function of the Code.

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 the source code differences between the linux-2.6.28.8.orig/NET/SunRPC/and the linux-2.6.28.8/NET/SunRPC/directories. unlike a single file, if you modify multiple files, you need to copy the entire Linux source code tree.

Parameters:

-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. Patch

In the generated patch, 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

  • Previous: Add busybox tool for Android
  • Next article: Linux kernel compilation option (1): General setup
  • Related Article

    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.