Detailed usage of diff command in Linux

Source: Internet
Author: User
Tags comparison diff

Diff command is the foundation of version management tools, this article mainly explains the diff comparison several ways and git diff use skill.
The following two documents, File1 and File2

$ cat File1
Aa
Aa
Aa
Aa
Aa
$ cat File2
Aa
Aa
Bb
Aa
Aa

1. General format diff file1 File2
$ diff file1 File2
3c3
< AA
---
> bb

Description: 3C3 indicates that the 3rd row of the File1 is changed (change), and the 3rd row of the file2 is;< to remove the row from File1;---split file1 and file2;> indicates that the line was added to File2
2. Context Format diff-c file1 file2
$ diff-c file1 file2
File1 2016-04-04 15:56:25.203923276 +0800
---file2 2016-04-04 15:56:47.647138613 +0800
***************
1,5 * * * *
Aa
Aa
! Aa
Aa
Aa
---1,5----
Aa
Aa
! Bb
Aa
Aa

Description
(1) The first two lines represent the basic information file name and time of the comparison file. "* * *" indicates the document before the change, "---" means the document after the change.
File1 2016-04-04 15:56:25.203923276 +0800
---file2 2016-04-04 15:56:47.647138613 +0800

(2) *************** that the basic information and change information are separated
(3) * * * * 1,5 * * * * * * * * * * from line 1th, contact 5 lines
(4) If it is an exclamation point (!), indicates that the line has changed, if it is a minus sign (-), indicates that the row was deleted, and if the plus sign (+) indicates that the behavior is new.
3. Merge mode diff-u file1 file2
In order to solve a large number of content repeated display and introduced, Git is the use of derived merge mode
$ diff-u file1 file2
---file1 2016-04-04 15:56:25.203923276 +0800
+++ File2 2016-04-04 15:56:47.647138613 +0800
@@ -1,5 +1,5 @@
Aa
Aa
-aa
+bb
Aa
Aa

Description
(1) indicating the basic information of the document, "---" means the document before the change, "+++" means the document after the change.
---file1 2016-04-04 15:56:25.203923276 +0800
+++ File2 2016-04-04 15:56:47.647138613 +0800

(2) The change of position at the end of the first with two @, " -1,5" indicates that the first file from row 1th of 5 consecutive rows, "+1,5" indicates that the second file from the 1th line of continuous 5 rows
@@ -1,5 +1,5 @@

(3) Change the specific content, the minus sign indicates that the first file deletes the row, the plus sign indicates that the second file is new.
Look at the Version management tool git diff effect:
Diff--git A/file1 B/file1
Index a57a69a. 863575a 100644
---a/file1
+++ B/file1
@@ -1,5 +1,5 @@
Aa
Aa
-aa
+bb
Aa
Aa

Git diff Common comparison method
git diff #工作区和暂存区比较
git diff master #工作区和master分支比较
git diff head #工作区和HEAD比较

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.