Diff and patch are two separate tool that are often use together, particularly in software development. The use of these tools can ease up the process of recording differences and applying changes between two files.
diff is a tool that can be use to create a “diff” or “patch” file that contains differences between two files. Though diff can write into many different format, most people will prefer the unified format as it is easier to work with.
patch is another tool that complements diff, it will apply the differences in the “patch” file to the target file. Think of it is a way to “patch” your old files with newer modifications.
The guide below is the simplest way to use diff and patch. Though the information provided here is incomplete, I believe it can get you started in using them in your project.
How to use diff
The basic use of diff is,
diff -u original.txt modified.txt > file.patch
If you want to use diff against two source tree, the command is,
diff -rupN original modified > program.patch
How to use patch
To apply the patch, change into the same directory as the unmodified file and execute
patch < file.patch
This is how to apply patch to an entire directory,
patch -p0 < program.patch
Patch applied can be simply removed by adding the -R switch,
patch -p0 -R < program.patch
patch -R < file.patch
For the explanation of using the -p
Other reference : LinuxJournal
Comments are closed.