[Post] Use and create a patch file

Source: Internet
Author: User

When I went to QQ today, I found that Eva could not be used. Later I saw a solution, so I wanted to make a patch, but it would not be :-). Later I checked and found out, wrote a summary, shared it, and did not know that there was no such thing in the past. I hope this is not unnecessary.

Create a patch file:

Code: Diff-Naur old directory new directory> patch file
Or
Diff-Naur old file new File> patch file

Restrictions on directory Layers


When creating a patch, the folder layers should be the same, for example

Code: --- old/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000

This is acceptable.
While

Code: --- old/try1/other/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000

This may cause some problems.

How to Use patch
There are two common usage methods for a patch file:
1.

Code: CAT New-patch | patch-P0

2.

Code: patch-P0 <New-patch

The number of layers in the patch command (-P0? -P1 ?)
Parameter-P to specify the layer from which the comparison starts. For example, the patch header of a patch file is as follows:

Code: --- old/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000

If the-P0 parameter is used, it indicates to find a directory named new from the current directory, find a directory named modules under it, and then find a directory named pcitablemon under it.
If the-P1 parameter is used, the first layer is ignored. Find a directory named modules from the current directory and find a directory named modules under it. This will ignore the new directory mentioned in the patch header.
And so on.

Patch file structure
Patch Header
The patch header contains two lines starting with ---/++ to indicate the files to be patched.
Multiple patches in a patch file
A patch file may contain many sections starting with ---/++, each of which is used for a patch. Therefore, a patch file can contain many patches.
Block
The block is the part to be modified in the patch. It usually starts and ends with something that does not need to be modified. They are only used to indicate the location to be modified. They usually start with @ and end with another block or a new patch header.
Block indent
Blocks will be reduced into one column, and this column is used to indicate whether to add or delete this row.
First column of the block
+ Indicates that this line is to be added.
-Indicates that this row is to be deleted.
There is no plus sign or minus sign, indicating that this is just referenced and does not need to be modified.

Example of a patch

Code: Diff-u old/modules/pcitable new/modules/pcitable
--- Old/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000
@-+ @@
0x0e110xae10 "cpqarray" Compaq | smart-2/p raid Controller"
+ 0x10000x0010 "cpqarray" Compaq | integrated array controller"
+ 0x10110x0046 "cpqarray" Compaq | smart-2/p raid Controller"
0x0e110xae32 "tlan" "Compaq | netelligent 10/100"
0x0e110xae34 "tlan" "Compaq | netelligent 10"
0x0e110xae35 "tlan" "Compaq | integrated NetFlex-3/P"
@-21,6 + 23,7 @@
0x0000x000f "ncr53c8xx" "symbios | 53c875"
0x10000x0012 "ncr53c8xx" "symbios | 53c895a"
0x0000x008f "ncr53c8xx" "symbios | 53c875j"
+ 0x0000x000a "sym53c8xx" "symbios | 53c1510"
0x10000x0701 "yellowfin" "symbios | 83c885 Gigabit Ethernet"
0x10000x0702 "yellowfin" "symbios | yellowfin G-NIC Gigabit Ethernet"
0x10110x0001 "Tulip" "Dec | decchip 21050"
--- Old/usr/share/kudzu/pcitablesun Sep 26 17:11:23 1999
++ New/usr/share/kudzu/pcitabletue Dec 19 20:05:41 2000
-15,6 + 15,8 @@
0x0e110x3034 "unknown" "Compaq | qvision 1280/P"
0x0e110x4000 "unknown" "Compaq | 4000 [triflex]"
0x0e110xa0f3 "Ignore" "Compaq | triflex PCI to ISA bridge"
+ 0x10000x0010 "cpqarray" Compaq | integrated array controller"
+ 0x10110x0046 "cpqarray" Compaq | smart-2/p raid Controller"
0x0e110xae10 "cpqarray" Compaq | smart-2/p raid Controller"
0x0e110xae29 "unknown" "Compaq | MIS-L"
0x0e110xae2a "unknown" "Compaq | MCM"
@-+ @@
0x0000x000f "ncr53c8xx" "symbios | 53c875"
0x10000x0012 "ncr53c8xx" "symbios | 53c895a"
0x0000x008f "ncr53c8xx" "symbios | 53c875j"
+ 0x0000x000a "sym53c8xx" "symbios | 53c1510"
0x10000x0701 "yellowfin" "symbios | 83c885 Gigabit Ethernet"
0x10000x0702 "yellowfin" "symbios | yellowfin G-NIC Gigabit Ethernet"
0x10000x0901 "unknown" "symbios | 61c102"

Analysis
In this example

Code: Diff-u old/modules/pcitable new/modules/pcitable

Created. However, it is best to use the diff-Naur command instead of diff-U.
It modifies two files: New/modules/pcitable and new/usr/share/kudzu/pcitable.
The first patch header contains two blocks, each with two lines added and one line added.
From http://www.linuxsir.org/bbs/showthread.php? T = 240802

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.