A

Basics about using Subversion

I just learned the basics of using Subversion (SVN) and would like to share the same with anyone in need. Subversion terminology All the files are stored centrally on a repository on the server running SVN. From that repository anyone can check out a copy of the source code files onto their local computer but […]

I just learned the basics of using Subversion (SVN) and would like to share the same with anyone in need.

Subversion terminology

All the files are stored centrally on a repository on the server running SVN. From that repository anyone can check out a copy of the source code files onto their local computer but only the owner has the authority to check in. This means that everyone can have a copy of the source files to use but only the owner has the authority to submit changes to the source code files which will be available to everyone else.

Every time the owner makes a change in subversion, it is marked as a change and assigned a number so that anyone can view this change directly or compare it with a change at a different time by its respective assigned number. This is how subversion keeps track of the changes.

Basic maintenance hierarchy consists of the following:

  • Branches
  • Tags
  • Trunk

The latest version copy is kept in the trunk folder and the releases are stored under the Tags and Branches folder for accessing a particular state of the ever changing source code. Like when you have made enough modifications on your files which were under version 1.7 to call it as version 1.8, then you can just tag it as 1.8 version and copy the files in a sub-directory 1.8 under Tags and similarly when the version change is a major one, it can be copied to a sub-directory 2.0 under Branches.

SVN Commands

On Windows, you can use Tortoise SVN to work with SVN in a graphical interface and doesn't need any commands as such. And if you are on linux (I am on Ubuntu), you can use a terminal to work with SVN (the most powerful way, in my opinion).

Create a local directory on your computer to keep a copy of the repository.

$ mkdir project1

Check out the repository.

$ svn co http://svn.ashfame.com/project1 project1
> A  project1/trunk
> A  project1/branches
> A  project1/tags
> Checked out revision 12.

("A" in front of output indicates "add") All of the directories from the central repository has been added to your local copy.

Put everything in the trunk/ directory for now. If you want add more files to the repository, then you can just copy them over.

$ cd project1/
project1/$ cp ~/plugin.php trunk/plugin.php

Tell subversion to add those files (new) back into the central repository.

project1/$ svn add trunk/*
> A  trunk/plugin.php

Now check in the changes (also known as commit) back to the central repository. You can use -m switch to specify a message to the commit.

project1/$ svn ci -m 'Adding plugin file'
> Adding trunk/plugin.php
> Transmitting file data .
> Committed revision 13.

Let's move forward with some more commands

Generally the case is that more than one people has access to commit to the project, so its necessary a bit to keep track of things.

To make sure you have the updated copy, just issue this command when you are inside the directory where SVN is setup.

$ cd project1/
project1/$ svn up
> At revision 16.

If there had been changes in the central repository, they would have been downloaded and merged into your local copy. Notice the revision number here, this will be different than your last commit if someone else has committed to the project since your last commit.

Anyways, make changes in your file

project1/$ nano trunk/plugin.php

To check different between your local copy and the central repository, you can issue this command

project1/$ svn stat
> M  trunk/plugin.php

( "M" for "modified") This indicates that the file is different from the copy from the central repository.

You can even see what exactly has changed in that file, so we can check it over and make sure things look right.

project1/$ svn diff

To commit those changes in the central repository, issue this command

project1/$ svn ci -m "added support for X feature"
> Sending    trunk/plugin.php
> Transmitting file data ..
> Committed revision 17.

Let's assume you have made several changes and now would like to release it as new version, so lets tag it. First we will copy it to a sub-directory under tags.

project1/$ svn cp trunk tags/1.5
> A tags/1.5

Now, finally commit it.

project1/$ svn ci -m "tagging version 1.5"
> Adding         tags/1.5
> Adding         tags/1.5/plugin.php
> Adding         tags/1.5/main.php
> Committed revision 18.

All set! I hope you enjoyed the SVN experience by now and if you need any help then you can read the SVN book for comprehensive SVN instructions.