Using Subversion to Make Your Life Easier
Introduction
Have you ever found yourself stuck with a bunch of files, all edited at different places and different times, and tried to figure out which one is the most recent? Perhaps you have the same file at your office computer, on your USB drive (to take it home), on your home computer, and in your email outbox. Keeping all versions of your files synchronized can be a daunting task.
Thankfully there is a better way! A program called Subversion can keep track of multiple versions of files for you. It also lets you keep synchronized copies of the files on as many computers as you wish. Even more, if you ever need to look at a previous version of a file, you can check out a snapshot of the file repository exactly as it looked back then.
Subversion Overview
Subversion is based around a client-server architecture. This means that there are two parts to the system:
- The Subversion server. This program keeps track of all file repositories, lets you check-in and check-out files. It also keeps track of which users are allowed to work with each repository, and whether or not they are allowed to make changes, or only to see what is in the repository.
- Many Subversion clients. Any number of client computers can check-in and check-out files from a repository on the Subversion server. These clients can be running either Windows or Linux. (There might even be a Mac version of the client software out there, but I'm not sure.)
Now that you know what Subversion is and why you can't live without it, let's look at how you would install it.
Installing Subversion
For the sake of simplicity, I'm going to assume that you want to run both the Subversion server and all clients on Windows machines. You can certainly run the server and/or clients on Linux, but there are lots of other tutorials on the web that talk about this method.
The Subversion web site has a lot of good information about the installation. Also, there is a great book called "Version Control with Subversion" available for free online.
Instaling the Subversion Server
- You'll need to check out the Subversion download page first.
- Then check out the specific page for Windows downloads.
- At this time (2.20.07) I'd suggest getting the file called svn-win32-1.4.3.zip.
- Unzip the file to C:\Program Files\. This will make a folder called C:\Program Files\svn-win32-1.4.3\.
- Now at this point, you have all of the necessary program to use Subversion from the command line.
- We'll need a common place for the Subversion server to keep the database of all the repositories. So create a folder for them, for example C:\Repositories\. If you have a data partition (say, D:\) separate from your Windows operating system partition, it would be a good idea to put your Repositories directory there.
Setting up Subversion as a Windows Service
- NOTE: You'll need Administrator rights on your computer before proceeding. Talk to Kevin.
- The svnserve.exe program cannot be run directly as a Windows Server, so we need a wrapper program. An excellent one is the "SVN Service Wrapper for Windows", by Magnus Norddahl available here.
- Extract svnservice.exe program to C:\Program Files\svn-win32-1.4.3\bin\.
- Open up a command window (Start -> Run -> cmd), and do:
- cd /d "C:\Program Files\svn-win32-1.4.3\bin"
- svnservice.exe -install -d -r C:\Repositories\
- This last command takes any arguments after "install" and passes them directly to the svnserve.exe process. There are more options to configure, but all you really need to tell it is to run in daemon mode (-d) and that the place where all of your repositories is (-r C:\Repositories\). This location should be the same as the folder you created in the previous step. If you want to configure more options, type svnserve.exe --help for more information.
- Now all you need to do is start the service. net start SVNService.
- It's probably a good idea to set this service to automatically start itself at start-up. This way you don't need to remember to start it manually every time you reboot your computer.
- To do this, open up the Services snap-in in (Start -> Control Panel -> Administrative Tools -> Services). There should be a service called "SVNService". Double click on it. Set the "Statup type" to Automatic and click OK.
- At this point the Subversion server is all set up, though it doesn't have any repositories to serve yet. We'll set one up, but we need to install the Subversion client, TortoiseSVN, first.
Install TortoiseSVN
TortoiseSVN is a really nice Windows Explorer shell plugin that will show icon overlays on top of your file icons that show information about their current repository state. Green checkmarks on your files mean that they have not been modified, while red x's mean that the file has changed, and you need to update it to the repository.
- NOTE: You'll need Administrator rights on your computer before proceeding. Talk to Kevin.
- Go to the TortoiseSVN download page.
- Get the file called TortoiseSVN-1.4.3.8645-win32-svn-1.4.3.msi. (Or the 64-bit version if you're on a 64-bit machine.)
- Install it. Let it install to the default location, C:\Program Files\TortoiseSVN\.
- You'll probably have to reboot. See you in a few.
Now that we're back, you should see that TortoiseSVN has added a few items to your right-click menu. From now on, most everything with Subversion can be accomplished with the commands in the Subversion right-click menu.
Create a Repository
[Screenshot]
- Browse to C:\Repositories\ and make a new folder. The name of the folder will be the name of the file repository. For example, make a folder named "TestFiles". Right click on TestFiles, and select TortoiseSVN > Create Repository here...
- Chose Native Filesystem and contiue.
- Bingo! You now have a reposity, though it doesn't have anything in it yet.
Set the Repository Permissions
- You'll likely want to set permissions on your repository so that only you can read/write to it. So browse into the repository folder, and go into the conf directory.
- Rename passwd to passwd.conf. (It just makes it easier to open in Notepad if it has an extension.)
- Edit the passwd.conf file in Notepad. You'll want to have an uncommented (line doesn't start with a #) section that says:
- [users]
- username1 = password1
- username2 = password2
- The passwords are stored in plain text. So don't use a very valuable password. You can have as many users as you want.
- Next, edit the svnserve.conf file in Notepad. You should have uncommented lines that say:
- [general]
- anon-access = none
- auth-access = write
- password-db = passwd.conf
- The passwd-db entry is just the name of the file where your username/password pairs are stored. Don't worry about setting the realm.
Import Files
- Before you can check out files from a repository, you need to import the initial versions. Here the terminology is confusing -- the first time you add files to a repository, you import them, then every subsequent time you need to check them out.
- It's good practice to also have a designated place in which you check out your repositories, so create a folder called C:\Repo_Checkout\. Browse to this folder.
- Make a folder with a name identical to the repository you just created, called "TestFiles".
- Make a text file in it called test1.txt. Type anything you want in it.
- Back up to the previous directory level, and right click on the "TestFiles" directory. Choose TortoiseSVN > Import...
- You'll need to enter the URL of your repository here. Use svn://localhost/TestFiles, and provide a message like "Initial import." Subversion will let you add a comment to every new version of your file repository, so that you can go back to a previous version without a lot of hunting. Nice.
Checkout Files
- Now, browse into C:\Repo_Checkout\TestFiles\ and delete everything. (If this scares you at first, then copy everything somewhere else for the time being. But you don't need these files anymore since they have been imported into the repository.)
- Browse up one level and right-click on the TestFiles directory. Choose SVN Checkout..., and give it the URL of the repository. Select which version you want to check out (HEAD is the latest one), and click OK. TortoiseSVN should create all of the files in your repository for you, and they should all have green checkmarks.
If all of that worked, then you are well on your way to having a great file repository. I won't go into all of the details of how exactly to use Subversion -- please consult the book and other online resources for that. Best of luck!
Frequently Asked Questions
- Q. I am on a lab computer and don't have administrative access to install TortoiseSVN. What do I do?
- A. In this case, download and use RapidSVN. You won't have the cool icon overlays, though.
- Q. It seems that the SVN password is sent over the network in the clear. Can I use SSH tunnels to encrypt the connection?
- A. Of course! All you need to know is that the Subversion server listens on port 3690. (This is by default, and can be configured via a command line option to svnserve.exe.)
- Q. Can repository folder names have spaces?
- A. Nope.
If you have a question, shoot me an email at mattdvalerio@ieee.org. I'll put your question here in the FAQ if it will help everyone.
This page last updated on :
February 20, 2007
This page has been viewed :
343 times.
Top of Page