What is a patch?

When we make changes to the lab code handed out, we will distribute the updates via a patch file that you can apply. A patch file is essentially a delta of the changes made, generated as output of the program 'diff' comparing the original file to the newly modified version. For more information on diff and how to use it, check out the man page '$man diff'.

How do I apply a patch?

To apply a patch to your code, download the patch file to the directory with your code (e.g. /home/mike/cs111/lab1), and then from a shell do the following:

$cd /home/mike/cs111/lab1
$patch -p1 < patch_file

This will apply the changes to your copy of the files, keeping your changes intact. Pay attention the output from 'patch', as it will tell you if problems occur. If it can't patch parts of a file due to some conflicts, it will report the errors to the console and write out a .rej file, which will show you which lines it had problems on. '+' indicates a line the patch wants to add, '-' indicates a line it wants to remove (like the output of diff). You can then make these changes manually. In the event that the patch encounters errors, it will also write out a .orig file, which is your original unmodified file.

If you've already applied some of the recommended changes manually, it may warn that it appears you're trying to apply a duplicate patch. Please ignore these warnings and continue so your code receives the rest of the updates.

For more details about the patch command, read the man page: '$man patch'.

updated 4/21/05