Finding the difference between files, and patching
When multiple versions of a file are available, it is useful to highlight the differences between files rather than comparing them manually. This recipe illustrates how to generate differences between files. When working with multiple developers, changes need to be distributed to the others. Sending the entire source code to other developers is time consuming. Sending a difference file instead is helpful, as it consists of only lines which are changed, added, or removed, and line numbers are attached with it. This difference file is called a patch file. We can add the changes specified in the patch file to the original source code with the patch
command. We can revert the changes by patching again.
How to do it...
The diff
utility reports the differences between two files.
- To demonstrate diff behavior, create the following files:
File 1: version1.txt
this is the original text line2 line3 line4 ...