Monday, May 28, 2012

How to create a source tree patch with GNU diff/patch

First, make a copy of your source tree:
  $ cp -R libfoo.orig/ libfoo.new/

When you finished with modifications to libfoo.new/, generate GNU unified patch:
  $ diff -rupN libfoo.orig/ libfoo.new/ > libfoo-05282012.patch

To generate a unified patch against the CVS:
  $ cvs diff -u > libfoo-05282012.patch

The patch can be applied to the origianl source tree:
  $ cd libfoo/
  $ patch -p0 < libfoo-05282012.patch

To revert the patch:
  $ patch -p0 -R < libfoo-05282012.patch