Monday, November 12, 2007

Contributing a patch back to an Open Source project

I recently needed to contribute a patch back to an open source project I was working on, and since I wasn't familiar with using cvs from the command line I needed to research how to create a diff. I thought I would post my findings since it took me a while to find anything useful. First you will want to create a diff of the code you are contributing. For a single class you could do the following:

cvs diff -u myClass.java > myClass.diff

This creates a unified diff, which I have read most open source projects prefer, or the class you modified with what is current in CVS, and output the diff to myClass.diff.

If the class is not under CVS control, you can add the class and then run the following:

cvs diff -uN myClass.java > myClass.diff

If you have modifications to more than one class you can do a diff on the entire package by doing the following:

cvs diff -uN myPackage > myPackage.diff

This will recursively perform a diff on anything that is either added or under cvs control and write the output out to myPackage.diff.

You can also set how many lines of context you wish in your unified diff by doing the following:

cvs diff -u8N myClass.java > myClass.diff

No comments: