In a previous article, I explained why you should use source control. In this article I'll explain how you can use source control.
There are a great many source code revision control systems, each of them with their own advantages and disadvantages. Out of all of these, I'll be talking about Subversion, because:
- It's free.
- It is well-supported open software that runs on all the major platforms.
- There's a number of easy-to-use client applications.
- Extensive documentation.
- Had I mentioned yet that it's free?
Subversion can be used to set up a source control server, which can even be accessible over the Internet. However, in this article, I'll focus on setting up a local repository that does not require a server, meant to be used by a single person or a small group working on a local network.
For Windows users I recommend TortoiseSVN, a Windows XP File Explorer plugin. For those of you not using the Windows platform, don't worry. There are Subversion GUI frontends for a range of other platforms.
First, you need to download and install TortoiseSVN. You can find the latest Windows installer on the official TortoiseSVN download page. Just download the .msi file and run it. The default settings are quite alright, although if you're low on disk space you can safely choose not to install the additional icon sets and the dictionaries.
You'll have to reboot after installing.
Once you've rebooted, you'll find a bunch of new menu options in the File Explorer context menu, the pop-up menu that appears when you right-click an item, see image.
Now you'll have to pick a spot where your source repository is going to live. Create an empty directory somewhere, right-click and then select Create repository here.... It will ask you if you want Native filesystem (FSFS) or Berkeley database (BDB). You'll want BDB, unless your repository is on a network drive, meant to be used by more than one person. In that case, pick FSFS.
Next, pick a different spot where your checkout directory, aka working copy will be. This can be a new, empty directory, but if you have an exisiting project can also use that.
In case of a new project, pick SVN Checkout.... For an existing project, click Import.... In both cases, you'll be asked to provide the URL of repository. Just click the small ... button, and select the directory where you created your repository.
For an existing project, now delete all the files and folders in your project folder and then do a Checkout, just like with a new project.
The folder icon will change to indicate it's under source control. You can now freely create new files and folders and change them. When you're done, right-click your top-level folder and select SVN Commit.... A dialog will appear showing your changes and additions, see image. Check which new files you want to add to the repository, and optionally enter a message describing your change. When you click OK, your hard work will be committed to the repository.
If you're working on a project with several people over a network (remember, use FSFS for your repository) and you want to get the changes others made, use SVN Update.
If you want to revert to an earlier version, figure out the revision number you want to go back to using Show log or Repo-browser. Then use Update to revision... to retrieve the previous revision.
If you want a copy of your project without all those silly .svn directories TortoiseSVN creates to keep track of things, use Export....
And that's all there's to it, really.
If you have any questions, comments or additions to this article, please feel free to post a comment. If there's interest, I'll write an additional article explaining how to set up a source control server.