diff Command and Patch command

Source: Internet
Author: User
Tags diff

diff Command and Patch command

Linux is the one.

2.9.5 File Comparison command--diff

Diff command
Building a Web site without a database, on the Linux system we use the source code installed MySQL server. Soon we found that Google released a series of MySQL patches, which are very good and powerful, when we can't wait to update the new things to the system, then use the patch command to fix it . Water does not forget to drill people, the patch is how to do it? This task requires file comparison command diff to help .
Diff is used to compare the differences of two text files and is one of the cornerstones of code versioning. diff uses the dynamic programming algorithm to realize the difference comparison , the foundation of this algorithm is the longest common sub-sequence, the very complex

, if you are interested, you can read the "Introduction to Algorithms" from Kingman.
diff provides the normal (normal diff), Contextual (context diff), and merge (Unified diff) Three formats that tell you the difference between the two files. The normal format of diff is not easy to read, the contextual format of the diff in the case of high file similarity will show a lot of duplicate content, it is a waste of space.

In 1990, GNU diff first introduced the "Merge format" diff, using a similar

diff -urfile01_old file01_new > File01. Patch

The

Command merges the context of the pre-and post-change files to display. Let me take a look at the patch file that was generated after executing the Diff-ur.
72=== modified file ' configure.in '
---configure.in 2011-06-06 13:53:46 +0000
74+++ configure.in 2011-07-27 21:10:40 +0000
75@@ -361,15 +361,11 @@

77if test "$GCC" = "yes"
78then
79-# mysqld Requires-fno-implic It-templates.
80-# Disable exceptions as they seams to create problems with GCC and threads.
81# mysqld doesn ' t use run-time-type-checking, so we disable it.
82# We should use-wno-invalid-offsetof flag to disable some warnings from GCC
83# regarding offset () usage in C + + Which is done with a safe manner in the
84# server
85-cxxflags= "$CXXFLAGS-fno-implicit-templates-fno-exceptions-f No-rtti "
86-ac_define ([have_explicit_template_instantiation],
87-[1], [Defined by Configure. Use explicit template instantiation.])
88+ cxxflags= "$CXXFLAGS-fno-rtti"
89fi
91mysql_prog_ar

73-74 line is the basic information of the file.
---configure.in 2011-06-06 13:53:46 +0000
+ + + configure.in 2011-07-27 21:10:40 +0000
"---" means the document before the change, and "+ + +" means the document after the change.
75 the position of the change at the line with two @ as the first and end.
@@ -361,15 +361,11 @@
" -361,15" is divided into three parts: The minus sign represents the first file, "361" means line No. 361, "15" means a row of 15 rows, which means that the following is the first file starting from line No. 361 row 15. Similarly, "+361,11" indicates that the second file starts at line No. 361 in a row of 11 rows.
Starting with the 76 lines of the patch file, the context of the two files is displayed together, in addition to those rows that have changed. Each line is preceded by a flag bit, the null represents no change, the minus sign represents the row that the first file was deleted, and the plus sign represents the new row for the second file.

Patch Command
Patching with patch commands, though not complex, is an opportunity to test your character, sometimes not a single patch to successfully complete the software update.

1, first to choose a good update software version of the patch, the wrong version of patch is not up , for example, Google patch can only be added to some versions of MySQL.

2, next determine whether you need to patch layers, such as Google Patch Globaltransactionids features included in the Patch V3, but if only patch V3, compile is not pass, There is no way to play patches (V1->V2->V3) Onelayer at a level.

There are often application patches to the entire directory, do not forget to set the P level , because for the patch file, the need to patch the file on your computer path name on the computer to create a patch may be different,

The P-level tells the patch command to ignore several parts of the path name to correctly identify the file. For example, if you see such a file name in the Demo.patch file:

/home/fangru/Mysql-test/extra/rpl_tests/rpl_foreign_key.test


And you are currently working on

Mysql-test/extra/rpl_tests/rpl_foreign_key.test

Let's calculate the p-level by calculating that the remainder of the path delimiter should be deleted from the beginning of the path to match your working directory .

In this example, p should be 3, so you need to use patch –p3 < demo. Patch . In the event of a mismatch, patch generates a Rej file, and you can manually modify where the record failed .

Nginx Ngx_req_status-master Module Patching

Yum-y Install patch unzip GCC


cd/mydata/download/lnmppack/nginx-1.6.3
Patch-p1 </usr/local/nginx_upstream_check_module-master/Check_1.5.12+.patch
Patch-p1 </usr/local/ngx_req_status-master/write_filter.patch

diff Command and Patch command

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.