Saturday, August 10, 2013

how to patch your code ?

Some of you(programmers) might not have tried patching tools before. There are many tools exist for Unix and windows to do patching. I started an opensource project a few weeks back and had no idea of what tool should I use to patch my code when needed. After a few read, I have found some tricks to do a good patching.  

If you are using a Unix system, this method might be really helpful to patch. Assume your source directory name is "test" and one of your code contributors got the same source directory.Now, you make a replicate directory of "test" called "testm" and do some changes to the source inside it. After a unit test, you want to send the modified source as a patch to your contributor. 

Open up a terminal and change the location to the parent directory of "test" and "testm".

  •  diff -Naur test testm > testpatch1.patch

Send the "testpatch1.patch" to the contributor and they should apply this patch to their source. 

  •  patch -Np1 --ignore-whitespace -d test < testpatch1.patch

Note: In this "diffing" and "patching" approach, you can include not only changes but also newly added files to the patch.