Diff/patch supplement

Source: Internet
Author: User
Diff/patch

Use diff/patch to patch the code
1. Use of diff
Diff can complete the comparison function and generate patch files
Format: Diff [Option] oldfile newfile
Common options include:
-R recursively processes Directories
-U output is in a unified format. Diff has two formats: "traditional" and "unified". Currently, "Uniform" format is generally used. In comparison, the file generated in a unified format is large, but it contains more information, which is helpful for reading and positioning.
-N: The patch contains the entire new file.
-Patch A contains binary files.
Diff usually redirects to a file and uses the patch as the suffix, which is called a patch file.
Example:
/* Oldfile hello. C */
Void main ()
{
Printf ("Hello the world! ");
}

/* Newfile hello-new.c */
Void main ()
{
Printf ("Hello the world! ");
}

Use the following command to generate the patch file hello. Patch
$ Diff-u hello. c hello-new.c> hello. Patch

Diff can compare the entire directory to generate a patch file
For example, there are two directories: hello-1.0 and hello-1.1. Hello-1.1 is an update of hello-1.0.
Command:
$ Diff-runa hello-1.0 hello-1.1> hello-1.1.patch

2. Patch usage
The command to apply the patch to the original code is patch
Patch [-B] suffix

If the patch fails, the patch patches the successful rows, and the failed rows are saved. if the rej is a suffix, the file is folded and the backup of the original file is generated. If the rej is successful, no backup is generated. -Option B can specify the suffix.
Note: The directory where the patch is run should be consistent with that when the patch is generated using diff. For example, if the patch file is generated in the upper directory of the hello-1.0 directory, the patch file should also be created in this directory.

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.