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