Generating a patch of changes to one file
cp file file.orig edit file diff -u file.orig file | tee file.patch
Generating a patch of all changes in a directory
diff -ruN dir.orig dir.mod > all-changes-in-dir.patch
Applying a patch to a file
patch file < file.patch
Applying a patch to a directory
cd dir patch -p1 < /tmp/all-changes-in-dir.patch
Reversing that patch out again when it doesn't work
cd dir patch -Rp1 < /tmp/all-changes-in-dir.patch
There are some handy cvs diff commands:
and with git:
This can also give a crude way to reverse a change: use diff to make a patch file and then feed it to patch -R… but there are usually better ways. cvs update's merge options and git revert.
If you are using patch files without revision control much, you may find wiggle helpful: http://cgi.cse.unsw.edu.au/%7Eneilb/source/wiggle/