Open main menu

CDOT Wiki β

Changes

Working with Patches Lab

180 bytes removed, 11:49, 9 February 2010
Apply a patch
* Now create a patch containing the changes you just made using the so called '''unified''' format (-u), with 8 lines of context. By default the diff is printed to stdout, so you should redirect it to a file. Typically patches are created from the top of your source directory (e.g., '''src/''') so that they can be easily applied later (i.e., people don't have to figure out where to apply the patch, and can just use their tree's root directory):
 
$ cd src
$ cvs diff -u8p . > patch.txt
 
If you are using hg instead of cvs, you do it this way:
$ cd src
If the patch was created using cvs, do this:
 
$ cd src
$ patch -p0 < patch.txt
 
If the patch was created using hg, do this:
$ cd src
$ patch -p1 < patch.txt
* Here '''-p0p1''' means strip 0 1 leading directories from each filename in the patch (hg has a quirk which requires -p1 even though you'd use -p0 in the cvs case). We do this because we are in the same location (i.e., ./) as the person who created the patch. If the directories were mis-aligned, we would have to strip leading directories using -p1, -p2, etc.
* You can use the '''--dry-run''' option to test and see what would happen if you did apply the patch. Some people like to call patch with the -s or --silent or --quiet option (all do the same thing). This will suppress all output except error messages, and can make it easier to see which parts don't work.