Working with an SVN Repository using Tortoise SVN

Using a versioning repository is an essiential part of web development. Whether you are working with a team of developers or alone having copies of code stored by version history will save you at one point or another. This article will explain the basic usage of Tortoise SVN with an existing SVN repository.  This article will not go over the initial repository setup.

SVN Usage Diagram

This diagram illustrates the basic usage of an SVN repository.  Developers commit changes to the SVN and generally one person would be responsible for exporting to production at regular intervals.

svndiagram

To get started download and install the latest verison of Tortoise SVN. At the time of this article Tortoise SVN is only available for Windows. Other SVN clients are available for Mac users. You can also install Tortoise on any Hosting.com Windows Server allowing you to use the same SVN client for committing changes and publishing new code.

Once installed Tortoise integrates with Windows Explorer. You will find new SVN options when right clicking on or in folders.

SVN Repository Vocabulary

Understanding some key words is important to the overal process. Some terms used are not all that obvious.

Import: To copy files into a repository

Export: To copy files out of a repository without version data. This is particularly useful when coping files from a repository to a production environment.

Checkout: To copy files out of a repository with version data. The inital checkout creates your working copy. This is to copy the code from the repository to the computer you use for developing the code.

Add: To mark new unversioned file(s) for upload to a repository. The files marked for addition will be uploaded on the next commit.

Commit: To copy files that have a modified date more recent than what is in the repository. Commit also perform actions previously indicated by various function like add, delete, move, rename, …

Update: To copy files from that repository that have more recent changes than your local version

Importing your Code

There are two ways to get started with an existing repository.  You will either be checking out the code from the repository or adding code from your local computer.  For now we will assume you are working with an empty repository. Right click on the folder that contains your code and choose Import…

import0

Enter the repository’s URL. This is usually going to look like https:/svn.somedomain/path/to/trunk/ and click OK. Depending on the authentication method setup for this repository you may be prompted for a login and password.  Enter the login information and save the credentials to prevent being prompt each time.

import1

You will receive a screen that looks like this only yours should have several more files listed.

import2

Checking Out the Head Version

If the repository has an existing code base or if you just imported your code you are ready to create a working copy by doing the initial checkout.

Choose a folder for your local copy to reside. Right click on the folder and choose SVN Checkout…

checkout1

Enter the repository URL. The Checkout Directory should match the folder you started with. Leave the defaults for Checkout Depth and Revision on this first checkout. Click OK.

checkout2

Now that you have a working copy you can develop your code as you normally would.

Committing Changes

You can use any IDE or editor for updating and adding files to your code. As you reach milestones in your development you should commit all changes back to the repository.  When working with a team, others may have committed changes on the same files before you.  SVN prevents you from writing over your team members work by prohibiting commits from an outdated working copy. If this happens you will need to update your copy and merge changes before doing your commit.  The integration between windows explorer and Tortoise help you to determine if your code does not match the repository.  You will see a green check box on a folder if everything in the folder is up-to-date.

greecheck

You will see a red exclamation icon if you have files that contain uncommited changes. These icons also appear on the files themselves.

redcheck

To commit your changes right click on or in the folder and choose SVN Commit…

commit1

You will be presented with a list of files awaiting the commit.  Uncheck any files you don’t want to commit at this time. You can also add comments to explain what is being committed. Click the OK button to start the commit process.

commit2

Getting Files Back

When you need to bring back an old version of a file or simply replace files lost or damaged on your development computer the value of SVN really shines.  Right click and move your mouse over TortoiseSVN then choose Update to revision…

update2revision

This dialog will open:

update

From here click OK to get the latest revision back.  Alternatively you can enter a revision number to obtain a certain version of the files. Click the Show Log button to help find the revisions you’re looking for.

showlog