How diff and
patch WorkThe diff
program compares two versions of a document,
generating a set of differences that reflect the
changes that need to be applied to the old document
to make it identical to the new document.
A typical Unix command might look like this:
diff -c orig/document document > diff-set
This assumes that document is the revised version,
and that the original version resides in directory
orig.
The set of differences can be transported to
someone who has the original copy of the document. By
running the patch program, the document contents can
be updated to the new version:
patch < diff-set
The document will be updated, and the original
document saved under a different name, usually
document.orig.
Note that the concept of patching is in no way
restricted to textual documents like program sources
and Web pages. It can be applied to virtually
anything: books, programs, spreadsheets, and even
sound and video files. On the PDP-11, a special tool
called SIPP (Save Image Patch Program) was provided
by the vendor, and operating system updates were
issued as patches to be applied using this program.
Modern video compression techniques are based on
constructing the next image out of previous images by
changing whatever was modified. In any given scene,
most of the pixels stay the same from one image to
the next, which is why video can be compressed so
much.
diff and patch for Win32 and
the MacUsers of Windows 95, 98, and NT can fetch
a version of diff from http://www.itribe.net/virtunix/contributors.html.
A version of patch is available at ftp://ftp.linux.activestate.com/pub/staff/gsar.
This archive contains all the source code and a
pre-compiled binary.
Mac MPW (Macintosh Programmer's Workbench)
versions of diff and patch can be
found at ftp://sunsite.cnlab-switch.ch/software/platform/macos/src/mpw_c/.
|