patch is a open source tool used to apply bug fix, and diff is a tool for generating patch files.


When you do open source project ,after you made some bug fix ,you need to submit patch file:

1. prepare the original and the modified source code directory, say project.orig/ and project.mod/
2. make clean to remove the binaries
3. apply diff command at the root level of directory, and pipe them into a patch fileFor example:

diff -ru -xCVS -x’.#*’ -x’*.so’ -x’*~’ -x’*conf*’ -x’*.P*’ -x’Makefile*’ project.orig/ project.mod/ > project.patch

if you see unwanted diff of configure or binary files, add prefix -x to exclude those files as in the example.


To apply patches, copy the patch file to the source code root directory . (e.g. put project.patch to project.orig folder), then patch the source

patch -p1 < project.patch

to reverse the patch,add -R option

patch -Rp1 < project.patch