Using Subversion for your Source Version Control

The Three Basic Steps

Lets now assume that you have installed Subversion on your machine and that you have access to a Subversion repository on some server, here designated as: svn:// This address designates the root of your tree. The svn commands are launched from your console. The first command you should use is the one that list the content of the repository:
  > svn list svn://
This is for the root, but you can also list the content of any existing directrory, i.e.:
  > svn list svn://

STEP 0. Creating a new directory.

Creating a new directory: this is something you will do only when you start a new project. You want to submit the content of a directory (e.g. called myproject) to a new directory. We want to put everything under the existing test directory of the repository and we are located in the directory that contains the myproject directory.
  > svn import myproject svn:// 
                                        -m "Initial submission"
You have then created a new directory called projectX that contains the content of your local directory projectX. The last part of the command is a message that is used to specify what the submission is about; you have to include such messages every time you submit something to the repository.

If you follow the directory structure described in the previous section, then myproject should have contained the trunk, branches and tags directories; projectX in the repository will then also contain these directories.

STEP 1. Checking out a directory.

You wish to start working on your ProjectX. You are located in your work directory; you will then obtain the latest revision of the project from the subversion repository:
 > svn checkout svn:// 
This command will create a local copy of the project files in a new directory called mycurrentproject corresponding to the content of the trunk directory of the remote repository.

If you now go inside the newly created directory (here mycurrentproject ) you will notice that a new directory called .svn has been created; this one will be used by Subversion to keep track of your changes. Other .svn directories also exist in all subdirectories that have been checked out. The subsequent Subversion commands can then be applied to any directory that contains a .svn subdirectory. You have to locate yourself into this directory and issue a command which will then affect the files in this directory as well as all its subdirectories.

STEP 2. Editing.

At this point, you can start editing the files of your projects using your favorite editor. When you will submit your changes to Subversion, it will automatically update the files you have modified. However, you should never change the tree structure without letting know Subversion, that is when you add, delete, copy or move files or directories, you have to use Subversion commands.
> svn delete aFile.txt

> svn add aFile.txt

> svn copy aFile.txt thisDir/anotherFile.txt

> svn move aFile.txt thisDir/anotherFile.txt
When you apply these commands, you, in fact, schedule the corresponding tree changes to be made the next time you will submit your changes to the repository. If you never submit these changes, then they will never be applied to the projects on the repository.

Note also that when you work in team, you should always make sure that you are not making changes that conflict with the changes of another teammate; this is a question of proper project management. Although Subversion can help you to reconcile the conflicting files, this is a situation should be avoided.

STEP 3. Committing your changes.

Once you are done with your project work, you are ready to submit the changes you have made to the repository and thus create a new revision of the project.
> svn commit -m "Feature Y added"
Again, the message is there to inform about the nature of the changes made to the files in this revision. The modified files will be uploaded to the server and a new revision will be created that other users can, in turn, check out. In principle, this is as simple as this: you checkout! you edit! and you commit!

Top of the page


(c) Robert Laganiere 2011