Simple SVN Tutorial

Here is a quick user guide that shows the command snippets demonstrating the basic functionality provided by an SVN repository. This page will be organized by usage scenarios such as "how do I check out code?" or "how do I add a new file and check it it?".

Assuming that you are using an already configured SVN repository and that you have been provided the SVN's address along with your user's credentials. However, credentials may not be required if you are checking -out source code from a public repository such as SourceForge, but may be required for check-in rights.

Checking-Out Code From a SVN Repository

The first step in any SVN usage, is to check out (or in short form: co) your desired repository or branch. To do this from a pubic repository, execute the following command:

svn co svn://<YourSVNURL>/<whateverBranchOrTrunk> MyLocalCopyOfTheSVN/

From a private repository or a repository that uses credentials:

svn co svn://<YourSVNURL>/<whateverBranchOrTrunk> MyLocalCopyOfTheSVN/ --username=<YourUserName>

The above command will prompt you for your password and will also ask if you want to store it on the local host for reuse later.

Note: If you would like to check your modified code back into the repository, it is best to use your credentials from the beginning.

To check out a specific version of the repository, perform the following:

svn co -r 1234  svn://<YourSVNURL>/<whateverBranchOrTrunk>

If you don't have access to a graphical method to review the SVN logs or timeline, first you must check out the repository and review it using the following command:

svn log

Adding a New File or Folder To a SVN Repository

The primary method to add a new file or folder to a SVN repository (files or folders which do not exist within the SVN repository), first you must check out the repository, add the file(s) or folder and finally check in the newly created file(s)/folder.

  1. svn co svn://<YourSVNURL>/<whateverBranchOrTrunk> MyLocalCopyOfTheSVN/
  2. svn add newTextFile.txt
  3. svn add newDirectory/ (this could contain several new files or new folders)
  4. svn ci -m "Checking in newTextFile.txt and newDirectory"

In the above code block, there are a few short cuts: ci is short for check-in, and the -m parameter on the command line allows the user to specify the message that will be provided alongside the newly checked-in files which will be contained in the SVN logs. The line: svn add newDirectory/ will add all of the files within newDirectory, but you may also use wild cards such as *.

Another method to create a new directory on the SVN repository without creating the directory on your local host, is to use the following command:

svn mkdir -m "Create a new directory on the SVN server." svn://<YourSVNURL>/<whateverBranchOrTrunk/newDirectory

Note: The mkdir subcommand is an instantaneous commit, hence, the -m for SVN check-in message.

Updating My Local SVN Copy of The Repository

At some point, you may wish to update your local SVN repository so that newly created files/folders or any modifications made since the checkout will be present in your local SVN directory. You may run into commit issues where there is a local modification and the SVN server's repository has a different representation of that file - in this case: there has been a collision and you will either: have to accept the changes from the server, ignore this file or alternatively merge your changes into the file.

svn update <specificDirectoryOrFile>

Note: Wild cards can be used or granularity can be applied to update only specific sections of your local SVN repository

Deleting a File Or Folder In The Repository

The easiest way to delete a file or folder within the repository, is after checking out the repository or branch, you delete the desired item and check-in your changes.

  1. svn del SomeFile.txt
  2. svn ci -m "Deleted SomeFile.txt because it is unneeded."

Creating A Tag

A tag is a way to describe the status of an SVN repository at a given point in time - in other words, this means a you can create a human readable value to reference all of the files and their contents at a specified revision. A good example, you may need this functionality to provide a point of reference for the status of your repository at RC or release intervals - its simply more meaningful than just using a numeric revision number. Assuming the tags directory exists, execute the following command:

  1. svn copy -r=4 <whateverBranchOrTrunk/> tags/<TagName>
  2. svn ci -m "Adding my new tagged directory which will be located at tags/<TagName>"

Creating a Branch

A branch is a copy of the main-line repository or "trunk". It is often used by developers as a temporary place to store their modifications or code as they develop and test new features which will ultimately (hopefully) be merged back into the "trunk".

  1. svn copy trunk branches/MyNewBranch
  2. svn ci -m "My new private branch"
  3. ... Make some changes in MyNewBranch
  4. ... Navigate and assuming you are in the main directory
  5. svn merge ../branches/MyNewBranch
  6. ... And that there are no collisions or issues
  7. svn ci -m "Checking in merged changes from branch"

Exporting and Importing SVN Repositories

If you wish to export a copy of the SVN without the .svn directories that litter the local repository - perhaps for a backup or to distribute source code cleanly.

svn export svn://<YourSVNURL>/<whateverBranchOrTrunk>

Alternatively, you could check out the repository and run the following command within the directory:

find . -type d -name .svn -exec rm -rf {} \;

The svn import command allows you to import an uncommitted file or directory into the svn - one scenario is when you have exported a repository and need to get it "back in".

svn import myDir svn://<YourSVNURL>

Blog tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.