So lately I have been given some thought to how we use Subversion (SVN) in our web development, and features we don’t use nearly as often.
In web development, one big area where I don’t see us using a lot is branching, tagging, and merging. However, with our iPhone Apps, we use tagging and branching a lot. As I started to think why, one of the biggest things was the environment. Client development, especially with the iPhone, is double clicking on a project file for Xcode, and I’m ready to go. There is almost no hassle running trunk versus running a tag or branch. It is all the same.
Building against a website, however, is different. Your environment requires a lot more information and pieces. For me, I need to make changes to my host file (for custom domains), Apache/Nginx configuration, MySQL Connection information, etc. There is no file i “double click” and go. It is a pain anytime I need to change my local (or staging or even production) paths and settings.
This is where the svn switch command comes in handy, and is extremely important. It allows you to change your checked out working copy’s source (or url), while maintaining any local changes you may have made. You can tell the actual path, regardless of file or directory names, by doing an svn info command. The best way to understand is through examples.
Arg, should have made this a branch.
You’re working on a big change, such as completely rewriting your internal message system. Suddenly, your boss walks in saying “There is a bug we need you to fix and push live now!” It is a simple bug, but your trunk is only half way through a major change. What do you do?
- New Branch on Server – You need to make a new branch on the server based off the server’s version of trunk. It’s a simple copy function, while having it execute on the server:
svn copy -m “Branching for new email system” http://svn.example.com/trunk/ http://svn.example.com/branches/new_email_system/
- Switch your trunk working copy to new branch – This allows you to keep all of your current changes locally, but switches you to the branch version:
svn switch http://svn.example.com/branches/new_email_system/
- Commit changes to branch – Commit your changes to the repository which will be applied to the branch:
svn commit -m “changes to new message system.”
- Switch back to trunk. – Make sure you are still at your trunk. If you did an svn info, it would show the URL location at the branch. Execute the switch again:
svn switch http://svn.example.com/trunk/
- Switch between trunk & branch as needed – When you need to work on the trunk, switch to the trunk. When you need to work on the branch, switch to the branch. The great thing is you won’t need to change any URLs in your configs in apache and such, it will just work.
- When your branch is ready, merge into trunk – Perform a merge since the starting of the branch to the last revision in the branch, applying it to the trunk:
svn merge -r 100:125 path/to/branches/new_email_system path/to/trunk
- Test changes made by merge, then commit. – Test the changes locally, and when you are satisfied things went well, commit the merged changes to trunk: svn commit -m “new message”
- Continue Development – you are safe to proceed as usual.
Over the new few weeks I plan on posting more little tutorials and tricks of some more advanved SVN commands, and hopefully it can help some of my fellow team members. Let me know if you have any questions, or want to know how to do other things. But the bottom line is if you haven’t used the svn switch command, especially in web development, you are sorely missing out.