Version Control---diff and patch commands in Linux

Source: Internet
Author: User
Tags diff file diff

I. Construction of two files for testing

Hello.txt:

World.txt:

Two. Compare the differences of two text files with the diff command

Perform the diff ' command on this two text file and save the difference in the Diff.txt file with output redirection

$ diff-u hello.txt world.txt > Diff.txt

The parameter-U is to make the differential output with context

1th, the three minus sign in line 2 identifies the original file, and three plus signs identify the target file;

The 3rd line indicates that in this difference section, the line from line 1th of the original file starts at 3 lines, and the target file is from lines 1th to 3rd;

A minus sign starting at line 4th indicates that only the fields that appear in the original file, the plus sign represents only the fields that appear in the destination file, and the lines without the minus sign represent the same fields as two files;

Three. Recovery of files

1. After deleting the target file world.txt, use the patch command to restore the original file hello.txt and the diff file diff.txt

2. After deleting the original file hello.txt, use the patch command to restore the target file world.txt and the diff file diff.txt

Four. Summary

1. diff and Patch commands can also be used to compare directories;

2.diff and patch command defects are not able to process the binary files;

3. Of course, the source code version control is now using centralized version control SUV or distributed version control git

Version Control---diff and patch commands in Linux

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.