In an open source world, if you are interested in contributing to an open source project by developing the source code first of all you need to build the source code. Then you have to submit the code you developed for that project through a patch or directly changing the code. If you are not a commitor for that project you can't directly change the source code. A commitor is a person who has source code modification rights for a open source project. If you are not a commitor then you have to submit what you have done through a patch.
A patch is a textual format file which contains the modifications has been done related to the original source code of a software project in open source terms. An example of an patch is as follows.
--- Rakefile (revision 752423)
+++ Rakefile (working copy)
@@ -175,6 +175,12 @@
+ web_inf.include project("bpel-schemas").path_to("src/main/xsd/dmapi.xsd")
+ web_inf.include project("bpel-schemas").path_to("src/main/xsd/breaks_bdi_bpel.xsd")
+ web_inf.include project("bpel-schemas").path_to("src/main/xsd/common_bpel.xsd")
+ web_inf.include project("bpel-schemas").path_to("src/main/xsd/java_util.xsd")
In a patch file it contains details on what lines have been added with a “+” sign and what lines have been removed with a “-” sign.
Let see how to create an patch file first. As I mentioned earlier first of all you have to build the source code of the project. Here you may use an version controlling software like “SubVersion” to manage and update your local source code with the online source code repository. This version controlling tool can used to create a patch for the modifications what you have done in your local source code. In SubVersion the command is as follows.
svn diff > bug-x-free.patch
The above command will create a patch file named “bug-x-free.patch”. For more details on creating custom patches can be found on here.
Then that patch file can be submitted through the particular project issue tracker (like JIRA, Bugzilla etc.)
Then the patch will be examined by a project commitor and added to the source code.
Note: Be careful to test the local modified source code whether it's working OK before submitting the patch.
Suppose you need to add a patch file to your local source code, then you can use the following command at the root of your source directory to add the patch the source code.
patch -p0 -i bug-x-free.patch
Then your source code will be modified based on the patch file.
Suppose then you want to revert the patch you added. The reverting functionality is not supported by patch command it-self. Then what you can do is to interchange the “+” with “-” in the patch file to revert the changes as those “+” and “-” signs are used to denote the added code line and removed code lines in the source code. Then again by using the above patch command you can revert the modifications occurred by the original patch file.