Git diff (---and + + + specific explanations)

Source: Internet
Author: User

If the two file similarity is very high, then the context format diff, will show a lot of duplicate content, it is a waste of space. In 1990, GNU diff pioneered the "Merge format" diff, which combines the context of F1 and F2.

It is used by adding U parameters (representing unified).

$ diff-u F1 F2

The results appear as follows:

---F1 2012-08-29 16:45:41.000000000 +0800
+ + + f22012-08-29 16:45:51.000000000 +0800
@@ -1,7 +1,7 @@
A
A
A
-A
+b
A
A
A

The first part of it is also the basic information of the document.

---f12012-08-29 16:45:41.000000000 +0800
+ + + f22012-08-29 16:45:51.000000000 +0800

"---" means the document before the change, and "+ + +" means the document after the change.

The second part, the position of the change with two @ as the first and end.

@@ -1,7 +1,7 @@

The preceding " -1,7" is divided into three parts: the minus sign indicates the first file (that is, F1), "1" means line 1th, and "7" means 7 rows in a row. Together, it means that the following is the first file, starting from line 1th, 7 consecutive lines. Similarly, "+1,7" means that after a change, the second file becomes a row of 7 lines starting from line 1th.

The third part is the concrete content of the change.

A
A
A
-A
+b
A
A
A

In addition to those rows that have changed, the context displays 3 rows. It merges the context of two files together, so it's called "Merge format." The first flag bit of each line, empty represents no change, minus indicates the row that the file was deleted from, and the plus sign represents the new row for the second file.

Six, the Git format diff

Version management system git, which uses a variant of merge format diff.

$ git diff

The results appear as follows:

Diff--git A/f1 B/f1
Index 6f8a38c: 449b072 100644
---a/f1
+ + B/F1
@@ -1,7 +1,7 @@
A
A
A
-A
+b
A
A
A

The first line represents a diff that results in a git format.

Diff--git A/f1 B/f1

Comparisons are made of the F1 of version a (i.e. before the change) and the F1 of version B (i.e. after the change).

The second line represents two versions of the GIT hash value (the 6f8a38c object in the index area, compared to the 449b072 object in the Working directory area), and the last six digits are the object's schema (normal file, 644 permissions).

Index 6f8a38c: 449b072 100644

The third line represents the two files that are compared.

---a/f1
+ + B/F1

The "---" represents the pre-change version, and "+ + +" represents the changed version.

The following lines are the same as the official merge format diff.

@@ -1,7 +1,7 @@
A
A
A
-A
+b
A
A
A

Git diff (---and + + + specific explanations)

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.