Branching, Merging and Restoring branches with SVN.
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, 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 in my opinion. Below, I am listing just a couple ways that you could use branching. In this blog 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
1. Creating a new SVN 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:
2. Merging from trunk to your branch:
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"
3. Merging your branch to the trunk:
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"
4. Deleting a branch:
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"
5. Restoring a deleted branch:
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"
6. Small Tips:
- Lets say you have been merging and diverging away from trunk frequently and when you are trying to merge trunk in your branch and you see a tree conflicts. What I would do is backup the file text conflicts:
svn resolve --accept working
Then you might want to update the files appropriately and commit the code.
- When you work on merging, merge as frequently as you can. I would check for updates to the trunk every 2-3 days and bring the incoming from trunk to your branch.
- If you are working in a team. I would merge when all the team members are present.
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.