Diff is a utility for comparing different files, and producing a resultant change file. It is part of CVS system, and is available on most *nix systems.

Step 1 ~ Simple patch for two files
Assuming you have file1.php and file2.php, and file2.php is the corrected version of your code, to create a diff patch of the two versions you can issue the following command:

diff -u file1.php file2.php > file1.patch

you can then send that patch to anyone with file1.php; they can then apply the patch by cd-ing into the dir with file1.php in it and issuing this command:

patch < file1.patch

This will then bring their file1.php inline with your patched version, namely file2.php

Step 2 ~ Patching directories of differences
If you have a release of code in a directory code_1_0 and a patched / updated version in a directory code_1_1, it is possible to diff the entire directories and create a patch as follows:

diff -ruN code_1_0 code_1_1 > code_1_0.patch

This patch can then be sent to anyone with the initial release of code_1_0 and can be applied to bring their source inline with your code_1_1 directory by cd-ing into their code_1_0 dir and running:

patch < /location_to/code_1_0.patch

diff is a great little app as the output patch file can easily be sent via email as it's simple ASCII text

If you want to make a big patch, including multiple diffs, you can use cat to sum them into one, big diff-patch.

cat 1.diff 2.diff 3.diff > big.diff #for summing them into one big one
cat 1.diff 2.diff 3.diff >> big.diff #for adding diffs to a existing diff

Step 3 ~ If you want to reverse your patch:

patch -R < 1.diff
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki