Handy Subversion Commands

Create And Import Into a New Subversion (SVN) Repository:
Replace ‘$repos_name’ with the name of your SVN repository – typically the name of the project folder.
(Note: For further repository admin functions and general SVN admin, see here).

$ svnadmin create /var/svn/$repos_name
 
#Note: To remove a repository, simply delete the directory directly as root user: (don't do this now unless you want to remove it :-):
sudo rm -R /var/svn/$repos_name

The recommended organization for a repository is to use the folders trunk, branches and tags, which we create using:

$ svn mkdir file:///var/svn/$repos_name/trunk
$ svn mkdir file:///var/svn/$repos_name/branches
$ svn mkdir file:///var/svn/$repos_name/tags

Now let’s import our project folder to this repository’s ‘trunk’ (main development line) folder): We do this the FIRST TIME we want to start tracking a project in the repository.

$ svn import localProjFolder file:///var/svn/$repos_name/trunk

Checking Out a Folder From a Repository:

Before having a local ‘working copy’ we need to check out the project folder for the first time:

$ svn checkout file:///var/svn/$repos_name/trunk {optional: localProjFolder}

Now we have a local working copy our project. We can make whatever changes we like, as in a usual file system structure. Note that any changes, APART FROM A STRAIGHT MODIFICATION TO A FILE (using a text editor for example), needs to be preceded by an ’svn’ to the command. For example, ’svn mkdir’ needs to be run to add a directory to the project. This is because SVN needs to be made aware of these changes.

Editing A File

Let’s say I have edited the file SecNew. java. We can now check the status of scheduled changes to our folder by running:

$ svn status
M      SecNew.java

In the above, we can see that the file SecNew.java was modified (in the working copy), and is due for modification in the repository.

Add A Folder To Our SVN Project

Let’s now add a folder to our project. I am going to add ‘custom’ to the folder SDCommon/src/org/:

$ svn mkdir ~/workspace/SDCommon/src/org/custom
A      custom

Note how I used ’svn’ before the usual ‘mkdir’ command. Remember, only pure editing of files does NOT require this preceding ’svn’ to be used.
The last line shows us that the folder was successfully created and is scheduled to be (A)dded to the repositoy.

Seeing What Changes We’ve Made To Our Folder: svn status & svn diff

Simply run the ’svn status’ command:

$ svn status
M      SecNew.java
A      custom

We can see the changes that are scheduled to be made to the repository on a commit.

Let’s now check out what specific changes have occurred to files that have been modified (SecNew.java in this case):

pacific@mainbox:~/workspace/SDCommon/src/org$ svn diff
 
Index: SecNew.java
===================================================================
--- SecNew.java (revision 6)
+++ SecNew.java (working copy)
@@ -5,6 +5,8 @@
 import org.apache.log4j.Logger;
 
 public class Security { //can be overridden if need be
+       protected DateTime StartDate = null;
+
        protected String ticker = null;
        protected String exchcode = null; //yahoo ec
        protected String name = null;

Lines that have a ‘+’ next to them, have been added. (a ‘-’ indicates lines that have been removed).

Leave a Comment