Version control is a critical part of any successful development team. You might think that your project is small or that no one else will be joining the team so version control is not needed. This is dangerous thinking because the future is always surprising. Your assumptions may be wrong but even if they are not, a good version control system will still save you countless hours of rework and frustration. Note that I said a good system, many teams out in the wild are still wasting time with Microsoft’s visual source safe (VSS) every day.
Historically CVS has been the system of choice for those wanting something reliable with a low cost. CVS does a much better job than VSS in almost every way, (cost, reliability, features). If you have ever tried to use VSS remotely or had multiple developers changing the same files you know what I mean.
CVS however has some limitations and Subversion has started to replace many installations. Subversion was designed to be a replacement for CVS and fixed some of the warts that it had. I highly recommend Subversion and I will be documenting my reasons here along with some good practices. Before I get started you should visit The Free Online Book which has been one of the most commonly referenced to documentation on the topic.
Subversion gets much of its power from simplicity. As you would expect the repository can contain any number of folders that contain other folders or files. These folders can be set up to represent almost any structure but the convention has been to set up 3 main folders for any given project; Trunk, Branches and Tags.
The Subversion(SVN) books to date have taken a different perspective on how these 3 folders should be used because none of this has been well defined by the SVN development team or source documents. Why should it be? How you use SVN depends greatly on what you expect to get out of it. The simple design of the product allows for many innovations helping us improve how developers work together.
Based on my experiences, I believe this is the best way to use SVN for a project.
- Trunk Keep the latest working copy in trunk unless this is a new project, in which case the folder is empty until your first commit. The code in trunk will always successfully compile and pass the automated unit tests. Developers, testers, management or anyone else who needs a reliable working copy can always go to trunk.
- Branches All development work requiring any significant time will be done in folders under the branches folder. The developers are free to commit their work daily or more frequently and even rollback without impacting the rest of the team. This frees them up to focus on the software instead of loosing any previous work. Once the new changes are done and tested the branch will be merged into the trunk. After the merged trunk is tested and those changes committed the specific work folder under branches can be deleted.
- Tags When significant milestones or external releases are achieved the trunk is copied to a specific folder under the tags folder. If legacy maintenance becomes necessary the tagged folder can be branched to complete the work. This will be critical if different versions of the project must be supported simultaneously.
- Backups are easy. If all the users are logged out svnadmin dump can be used for a reliable backup. If there are users who will not leave then svnadmin hotcopy can be used for a quick backup.
- Nothing is ever deleted. Even delete gets a revision number and you can always fetch old revisions even if the folder is no longer part of the current revision.
- Folder renames. Folders can be renamed while retaining their history.
- Atomic commits. When committing a group of changes to the repository they will all be done at once or none at all. This helps prevents anyone from getting a partial commit or broken copy of the code base.
- Fast light weight copy for branches Branches are light weight copies so they are cheap and made quickly. When you start making changes to the new branch only the difference from the master copy need to be kept saving time and hardrive space.
- Rollback is easy The merge command can be used to quickly rollback your working folder.