April 23, 2005

Version Control (part 2)

Following on from Version Control Part 1, here's a short article on how to set up Subversion, a simple to use, yet "industrial strength", version control system. These instructions are only for windows NT4/2000/XP; installing and setting up Subversion on other operating systems is similarly simple.

For more about Subversion and how to use it, read this book.

Download and install Subversion

Firstly, download and run the windows installer (currently here).

Create a new, empty repository

Open a command prompt.

Execute:

svnadmin create c:\svnRepository

(or whatever you want instead of "c:\svnRepository" - the article assumes "c:\svnRepository"). This will create a folder c:\svnRepository that Subversion will use to store it's versions of your files. Do not add, delete or edit any files in this folder or any of it's subfolders until you know what you are doing. This folder is quite different than any folder where you have files that you want to put in version control.

Set up subversion server configuration

Edit c:\svnRepository\conf\svnserve.conf

and add the following at the end of the file, starting on a new line and with no spaces at the beginning of each line:

[general] anon-access = none auth-access = write password-db = passwords.txt realm = myRealm

and create a file "c:\svnRepository\conf\passwords.txt" containing:

[users] aName = aPassword

replacing aName with whatever login name you want for subversion and aPassword as some password.

This will allow password protected access to read and write to the subversion server running on your machine from any other machine connected to it (e.g. over the internet) once the subversion server is running.

Run the Subversion server

Execute:

svnserve -d -r c:\svnRepository

This starts the subversion server for the subversion repository you just created at c:\svnRepository.

Install Tortoise - windows explorer integration

Now install TortoiseSVN - download and run the windows installer (currently here).

Creating a new folder in version control

I'll only describe one simple scenario - please experiment with TortoiseSVN (maybe even read the documentation) to find out more. The steps described may seem like a long list, but really it's all very simple and doesn't take long.

Open a windows explorer.

Select c:\

Right click TortoiseSVN > Repo-Browser

Type url "svn://localhost"

This now allows you to browse what's in your subversion repository a bit like windows explorer (but your repository will be empty now). In this example, I'll show you how to create a folder for files that you want to version control.

Select "svn://localhost" in the TortoiseSVN Repository Browser

Right click Create Folder...

Type the folder name myProject.

Click OK on the "create folder" dialog and also on the "log message" dialog.

You'll now see that the folder "myProject" has been added to the repository.

Press OK in the repository browser to close it.

Using the version controlled folder

Now, in the windows explorer, select c:\

Right click Checkout...

For the URL of the repository, click the "..." button to the right of the URL combo box - this opens the repository browser.

Press the + to the left of svn://localhost to expand the tree view of what's in the repository and select myProject.

Press the OK button on the repository browser.

For the Checkout directory, type C:\myProject - this will be where the files that you will work with will go.

Press the OK button - then a dialog will say that the folder doesn't already exist and do you want to create it - click yes on this and OK on the checkout dialog.

Create a new file in c:\myProject called "thing.txt" with some text in it.

In windows explorer, select C:\myProject

Right click Commit...

In the "enter log message" dialog that is opened, you can enter a message in the top section that describes what you are adding or changing. In the lower section, there will be a list of files that have been changed or could be added to version control. In this case, there will just be the file "thing.txt" with a status "non-versioned". Click in the checkbox next to "thing.txt" and press the OK button. Then click on the OK button of the "commit" dialog.

Editing files

Edit the text in "thing.txt".

In windows explorer, select C:\myProject\thing.txt

Right click TortoiseSVN > Diff

This will open a TortoiseMerge window showing the difference between the current contents of thing.txt and the version as it is in version control - i.e. it will show the edits that you have just done.

Close this window. If you wanted to throw away your changes since the most recent version of the file in the repository, then you'd select the file and Right click TortoiseSVN > Revert.

Right click Commit...

In the "enter log message" dialog that is opened, "thing.txt" will already be selected, and the status will now be "modified". Press the OK button on this dialog, and on the "commit" dialog too.

In windows explorer, select C:\myProject\thing.txt

Right click TortoiseSVN > Show Log

This opens a Log Messages dialog. This dialog allows you to see what changes were made between any two versions (just select two versions and Right click Compare Revisions.

That's all I'll write about for the moment - I'm hoping that's enough to get you started. I'd strongly recommend just trying out the menu options of TortoiseSVN and reading some of the documentation before using subversion for anything real.

In the next article in this short series I'll write about using version control in a team, which is where version control becomes even more vital and adds to the scenarios described here and in part 1.

Posted by ivan at April 23, 2005 5:21 PM
Copyright (c) 2004-2007 Ivan Moore