Version control is a must for projects such as ours with a geographically diverse team of developers each working on any number of these projects at the same time.
Subversion, because of its similarities to CVS, has made it easy for us to reap the benefits of version control with minimal effort. However, there is a lot more to subversion than update and commit. There is also branching and merging, but unlike CVS the concept is easier in subversion, at least, in my experience.
So when does branching become necessary or useful? Branching allows you to create a copy of the portion of your project to another location in the repository. This allows one developer to work on features that may not be part of the main line of development without disrupting the work of other developers.
As an example, I have Ajax File Storage 0.8 running on one of our client projects and they have recently requested for new features. Now I can just as simply work on the trunk or main line of development without branching but I'll probably have a hard time if I need to fix bugs and do minor tweaks. If I don't branch, I would have to cherry pick the changes I commit to the repository to ensure that unfinished code doesn't get committed and pushed to production.
So the safest and most appropriate solution is to create a branch of Ajax File Storage and work on the new features on this branch. Bug fixes and minor tweaks are then committed to the trunk or the main line of development.
Later on, when I am finished with the new features on the separate branch, I can use svn merge to merge changes from the branch back to the trunk.
Here's a step-by-step guide on how I went about branching and merging. But before trying this out, it would help if:
svn cp ajax-filestorage-ui svn+ssh://code@code.solutiongrove.com/home/svnrepo/solutiongrove/monitorex/branches/ajax-filestorage-ui -m "create a branch to work on new ajaxfs features"
svn switch svn+ssh://code@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/trunk/packages/ajax-filestorage-ui/ ajax-filestorage-ui/
At this pioint,
I can now start working on the new features.
After I'm done with programming, the next task will be merging changes back to the main line of development.
Before merging, I should look at the repository viewer and check what revisions in the branch I want to merge back to the trunk. Looking at http://code.solutiongrove.com/svn/viewvc.cgi/monitorex/branches/ajax-filestorage-ui/, I found out that there are 2 revisions, namely, 2557 and 2558 that I want to merge back to the trunk.
Here's how I went about merging:
svn switch svn+ssh://code@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/trunk/packages/ajax-filestorage-ui/ .
svn merge -r 2554:2557 svn+ssh://code@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/branches/ajax-filestorage-ui
svn merge -r 2554:2558 svn+ssh://code@code.solutiongrove.com/home/code/svnrepo/solutiongrove/monitorex/branches/ajax-filestorage-ui
If all goes well, then you would have an updated working copy with the changes from your branch. You should probably test the code and check to be sure that the merging worked.
You can then finally commit the changes to the repository using svn commit and svn update your production system.
svn commit -m "commit revisions 2558 and 2557, merge new features from branch to trunk"
svnmerge.py (in the contrib directory of the official svn svn repository) saves you *a lot* of pain, by tracking the appropriate merge revisions for you.
Svn 1.5 will do this for you also, but until then if you're not using svnmerge.py you're crazy ;)
http://www.orcaware.com/svn/wiki/Svnmerge.py
http://svn.collab.net/repos/svn/trunk/contrib/client-side/svnmerge/
by Mark Aufflick on 01/23/08
Thanks for the tip.
You're absolutely right. One lacking feature in subvesrion 1.4 and below is that it doesn't keep track of the revisions that have been merged to and from a branch or the trunk so you have to keep track of the revisions manually.
If you're not careful it's perfectly possible to remerge stuff that you have already merged before and you'll end up with lots of conflicts when you check status before committing.
That's where the python script comes in. It uses the svn:properties to keep track of which revisions have been merged to a branch or to the trunk.
by Hamilton Chua on 01/26/08
You may request notification for Solution Grove Blog.