August 28, 2012 3:27 pm
The modern day teams use modern version control system like Git and Mercurial and no question they are better in usability than the version control systems that were popular like 5 years ago something like an SVN. But if you are still using or if you have to use SVN and need to use features like branching this blog might prove to be of some help. Don’t panic it is not as bad as Git or other modern VCS’s hype it to be IMO. Below I am listing just a couple ways that you could use branching. In this article, I will be covering:
(a) Creating a new branch
(b) Merging from trunk to your branch
(c) Merging your branch to the trunk
(d) Deleting a branch
(e) Restoring a deleted branch
If you or your team are working on a new module and you would like to keep your trunk production you will go about create a new branch to work on. The process of creating a new branch and this assuming you would diverge from the trunk:
svn copy svn+ssh://host.example.com/sources/project
If you have an existing complete project then cd into your trunk and “svn update” it.
svn copy svn+ssh://host.example.com/sources/project/trunk svn+ssh://host.example.com/sources/project/branches /YOUR_NEW_CREATED_BRANCH -m "Creating a branch for "
The output of the above command would be similar to your The above command and done your new branch is created.
svn switch svn+ssh://host.example.com/sources/project /branches/YOUR_NEW_CREATED_BRANCH
to make sure a branch is checked out use:
svn merge svn+ssh://host.example.com/sources/project/trunk .
use the ‘–dry-run’ option to check the incoming changes without actually making the merge; use ‘-r:’ to merge revisions.
svn commit -m "Your merge commit message"
svn merge svn+ssh://host.example.com/sources/project/trunk svn+ssh://host.example.com/sources/project/branches /YOUR_NEW_CREATED_BRANCH
Again you could use the the flags mentioned above.
svn commit -m "Your merge commit message from branch to trunk"
Once you are done merging your branch -> trunk and cd into the project root dir
svn delete svn+ssh://host.example.com/sources/project/branches /YOUR_NEW_CREATED_BRANCH -m "commit message"
In case a branch needs to be restored and you need to lookup something.
svn copy svn+ssh://host.example.com/sources/project/branches /YOUR_NEW_CREATED_BRANCH@rev_num svn+ssh://host.example.com/sources/project/branches /YOUR_NEW_CREATED_BRANCH_restored -m "commit message for restoration"
svn resolve --accept working
Then you might want to update the files appropriately and commit the code.
I hope this has saved time for people reading this blog. I have some SVN knowledge under my belt and would be happy to answer the questions to the best of my knowledge.