Apache Subversion is an open source version control system, popular among many developers. Creating and applying patches for your source code is a significant task you might need to do at some point of coding, specially when working with large scale enterprise product source codes. This post is about how to use subversion to create a patch or apply a patch after doing some modifications into the source code.
First let's see how to see the differences made into our code. 'diff' command is used to view the all the uncommited changes done into a certain project folder.
To view these uncommited changes goto the relevant directory in the local project repository and type;
This will list all the modifications done into the source code with the specific class names.If we want to view the changes done to a single class or limited set of classes that can be viewed by adding those file names into our command as,
But note that we have to be in the correct directory where the files are located, before entering the command.
Another option is view the differences between two revisions of the project.This is done by giving the specific version numbers with the 'diff' command.
As an example let's say we need to view the changes between revision 112 and 113. Then use svn diff -r 112:113, this will list the changes between the two given revisions only now.
As we can see the changes now next step is creating the patch file which contains these changes. The changes can be applied to the another source code using a .diff or a .patch file. To create a patch for the modified contents in a whole directory, following command can be used.
If the patch is for some changes in a single file this can be,
There may be times that a patch is needed for the changes between two revisions. If so we need to give the necessary revisions with the command.
All the changes we did are safely written into a patch file now and they can be applied to someone else's code by applying this patch in the correct way.