OPERATING SYSTEMS ICOMS W4118, Dept of Computer Science, Columbia University
Home | Announcements | Lectures | Homeworks | Grades | Discussion | Resources

SOURCE CODE BACKUP USING DIFF
For version control and backup purposes you may find it helpful to create occasional "diffs" of your source trees. A diff gives you up to date information regarding the changes present between two files or directory structures.

In order to create your diff, you have to type out the following commands:

cd /usr/src
diff -pur [pure source tree] [new source tree] | grep -v "^Only in" > my.diff

Switches to diff

the p switch will have your output mention what functions the changes occur in (this will make your diff more readable), the r switch has diff work recursively down your directories, and the u switch specifies the "unified" output format.

Switches to grep

the v switch removes from grep's input anything that matches the string in quotes. We are removing whatever matches "^Only in" because there might be extra object or dependency files in your more current version of the sources - these files are not probably not relevant for patching purposes. The downside of this is that if you have a solitary file that you have coded up, it will not be included in the patch. Adding the switch "N" to diff (making it "diff -purN") will enable you to include your important files within your patch, at the risk of including the contents of many unnecessary files. If you want to do this, be sure to first "make" your pristine sources - with the same arguments to "make config" - so you can reduce the unnecessarily unique files.

The output of this command is redirected into a patch that you can reference and (hopefully) use to reconstruct your files by applying the patch to pristine sources like so:

cp my.diff /usr/src/linux
cd /usr/src/linux
patch -p1 < my.diff
Any error messages will tell you exactly what parts of the patch could not be applied do to formatting issues.

Switches to patch

The "p1" means to start patching at the current directory.

If you're still confused about diff and patch I'd advise you to see the info pages for them (their man pages are somewhat unfulfilling). In order to do that, please type "info {diff,patch}" at the command prompt, or, if you are in emacs, "C-h C-i" and then "diff". Type "info info" if you are unfamiliar with info.


Jason Nieh, nieh@cs.columbia.edu