Using Subversion (SVN) CLI on Linux

Working with Linux SVN client the simple way. 

Software

Software used in this article:

  1. Debian Wheezy
  2. Subversion 1.6.17
  3. Gnome-keyring 3.4.1

Installation on Debian

Install subversion if not yet installed:

# apt-get update && apt-get install subversion

We’ll use gnome keyring to store SVN passwords (another option would be kwallet):

# apt-get install gnome-keyring

Keyrings will be stored under ~/.gnome2/keyrings/.

Open ~/.subversion/config file and set password store to gnome-keyring:

password-stores = gnome-keyring

Open ~/.subversion/servers file and set the following parameters if needed:

[groups]
store-plaintext-passwords = no
username = sandy

[global]
store-passwords = yes
store-plaintext-passwords = no

Let’s create a myproject directory for our svn project:

$ mkdir -p ~/svn/myproject

Change to svn directory:

$ cd ~/svn/myproject

Starting this point, we’ll be working inside ~/svn/myproject.

SVN Usage

SVN co – Check out a working copy from a repository

Let’s checkout the latest version copy from the SVN server:

$ svn co https://svn.example.com/repository/myproject/ ./
Checked out revision 26.

As we may see below, there’s just one Python script checked out from the repository:

$ ls
code.py

Revision number is 26.

SVN mkdir – Create a new directory under version control

Create a new directory for scripts:

$ svn mkdir ./scripts

URL can also be used to create a remote directory if needed.

SVN status – Print the status of working copy files and directories

Check status:

$ svn status .
A scripts

We see that scripts is added (“A”) to version control. That’s what we just did, created a new directory for scripts.

SVN ci – Send changes from your working copy to the repository

Commit changes to the server:

$ svn ci -m "#no_task adding script folder" ./scripts
Adding scripts
Committed revision 27.

Revision has changed to 27. If we check svn status now, it should return nothing as no changes are made:

$ svn status .

SVN info – Display information about a local or remote item

Check local working directory:

$ svn info .
Path: .
URL: https://svn.example.com/repository/myproject/
Repository Root: https://svn.example.com/repository/myproject/
Repository UUID: b0ab59e6-bf21-43f5-ac60-c2f9a0b9eb90
Revision: 26
Node Kind: directory
Schedule: normal
Last Changed Author: sandy
Last Changed Rev: 26
Last Changed Date: 2014-03-13 17:29:52 +0000 (Thu, 13 Mar 2014)

We see the old revision number here, 26.

We can also check other files and folders individually by specifying them:

$ svn info scripts
Path: scripts
URL: https://svn.example.com/repository/myproject/
Repository Root: https://svn.example.com/repository/myproject/
Repository UUID: b0ab59e6-bf21-43f5-ac60-c2f9a0b9eb90
Revision: 27
Node Kind: directory
Schedule: normal
Last Changed Author: sandy
Last Changed Rev: 27
Last Changed Date: 2014-03-13 18:31:14 +0000 (Thu, 13 Mar 2014)

SVN up – Bring changes from the repository into the working copy

We can use svn update command to bring changes from the repository into the working copy:

$ svn up
At revision 27.

Display working directory info again:

$ svn info .
Path: .
URL: https://svn.example.com/repository/myproject/
Repository Root: https://svn.example.com/repository/myproject/
Repository UUID: b0ab59e6-bf21-43f5-ac60-c2f9a0b9eb90
Revision: 27
Node Kind: directory
Schedule: normal
Last Changed Author: sandy
Last Changed Rev: 27
Last Changed Date: 2014-03-13 18:31:14 +0000 (Thu, 13 Mar 2014)

Revision changed from 26 to 27, good.

SVN co – Check out a specific revision copy from a repository

Let’s see how our local copy looks like:

$ ls
code.py scripts

So we have a python script that came with revision 26, and a scrips folder that was created afterwards, revision 27.

Many bad things can happen, files get infected or corrupted, and sometimes there’s a need to get to the last know non-infected or non-corrupted copy.

We can checkout a specific revision copy, 26 in this case, from the server by adding a revision number:

$ svn co https://svn.example.com/repository/myproject@26 ./
D /home/sandy/svn/myproject/scripts
Checked out revision 26.

If we list items under the local working directory again, we’ll notice the following:

$ ls
code.py

The scripts folder is gone, as it did not exist on revision 26.

To get back to the newest revision, we don’t need to checkout again, but simply update:

$ svn up
A scripts
Updated to revision 27.

And we see that scripts folder is back.

SVN rm – Remove files and directories from version control

To remove scripts folder from version control do:

$ svn rm scripts
D scripts

Letter “D” indicates deleted.

Commit changes to the server:

$ svn ci -m "#no_task deleting scripts" .
Deleting scripts
Committed revision 28.

SVN diff – Display the differences between two revisions or paths

To get the idea of svn diff, we’ll create a test file with some text inside:

$ echo "some random text here" > ./test.txt

Add it to version control:

$ svn add ./test.txt
A test.txt

And commit changes to the server:

$ svn ci -m "#no_task test.txt" ./test.txt
Adding test.txt
Transmitting file data .
Committed revision 29.

Note the revision number 29. Let’s modify the test file by adding another text line:

$ echo "this is a second line" >> ./test.txt

And commit changes to the server again:

$ svn ci -m "#no_task test.txt updated" ./test.txt
Sending test.txt
Transmitting file data .
Committed revision 30.

Note the revision, 30. Now we can check the differences between the two revisions:

$ svn diff -r 29:30 ./test.txt
Index: test.txt
===================================================================
--- test.txt (revision 29)
+++ test.txt (revision 30)
@@ -1 +1,2 @@
some random text here
+this is a second line

We see that the latest revision has an extra text line.

SVN mv – Move and/or rename something in working copy or repository

In case we need to rename a file, or afolder, we use svn mv command:

$ svn mv test.txt newname.txt
A newname.txt
D test.txt

As may be seen above, newname.txt file is added to version control while test.txt is deleted from it.

SVN ls – List directory entries in the repository

To list the content of the repository:

$ svn ls https://svn.example.com/repository/myproject/
code.txt
test.txt

SVN cat – Output the content of specified files or URLs

To read file from the repository:

$ svn cat https://svn.example.com/repository/myproject/test.txt
some random text here
this is a second line

SVN help – Describe the usage of this program or its sub-commands

Check svn help for more available sub-commands.

Leave a Reply

Your email address will not be published. Required fields are marked *