A Guided Tour of Subversion (SVN)

Assuming the reader has already installed Subversion (SVN) and created a repository, the article offers a guided tour through the most important and frequent Subversion usage scenarios.

In this article I assume, that you already have the Subversion installed and that your repository is already created and accessible (see Part 2 for how to do that). I will use both command line client (svn) and TortoiseSVN (graphical client for Windows) in parallel to demonstrate multiple ways to do things. In the examples I will use the http: protocol to access Subversion (for which the Apache HTTP server is needed), but you can equally good use the svn: (you need to run Subversion's svnserve server) or file: (with no server) to go through the sample scenarios. The root URL of the repository in my examples will be localhost / repos /sandbox/ (it's the repository created in Part 2 examples).

All the source files used in this article are available in the attached zip file.

The first important command we should get familiar with is help. Both tools have rich help, which assist us to quickly find reference information.

### Command Line

svn help

### Tortoise SVN

Right Click -> TortoiseSVN -> Help

When starting the work with some repository, we usually wan to check, whether the repository URL is correct and to get oriented in the repository structure. With command line client we can use the info and list commands, with Tortoise the easies way is to use the build-in Repo-browser. When using http protocol, there is also the alternative to simply use web browser to examine the repository structure/content.

### Command Line

svn info localhost/repos/sandbox/

and after that

svn list -v localhost/repos/sandbox/

(and eventually -R for recursive listing)

### Tortoise SVN

Right Click -> TortoiseSVN -> Repo-browser -> type in the URL localhost/repos/sandbox/ -> OK

During the above use case the clients might ask for user name/password, if the anonymous read access is not allowed (depending on your access file - as explained in Part 2), in different setup they might ask later - when a write operation is performed. By default the user credentials will be remembered and asked for only once per repository (the credentials are stored in your home folder).

Once we know our repository, we can start by importing our project. Let's assume we have a Java project called Hanoi, which solves the well known Towers of Hanoi problem ( http://en.wikipedia.org/wiki/Towers_of_Hanoi). We have the project on our hard disk and we want to put it into Subversion repository. We have two options for importing data - either we just want to place files into version control or we want to place them into version control and turn the existing folders into SVN working copy, without moving the files. Let's go through the both cases. Firstly we will create the recommended project structure (trunk/branches/tags) by import, secondly we will turn the project folder into a working copy. Create the following structure in your temp folder:


Now we will import this structure into SVN.

### Command Line

cd \Temp

svn import structure http:// localhost / repos/sandbox/ -m "Importing the project structure"

The -m MESSAGE is common parameter for SVN commands which write data into the repository - you always have to specify the message. Try to execute the command without -m and see the result.

### Tortoise SVN

Right Click the "structure" folder-> TortoiseSVN -> Import... -> Enter the repository URL localhost/repos/sandbox/ and the commit message -> OK

Now we have the folder structure duplicated in the repository, but there is no connection between the files on our disk and in the repository - it's not a working copy - therefore there is no easy way to propagate changes from the temp folder to


About the author

AgileConnection is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.