Network programming @ Noppa | @ wiki - Updated: — Jussi Laakkonen 2012/08/22 10:59


Updates:

20.8.2012: Initial version
21.8.2012: Documented rest of the commands and added some file manipulation command documentation.
22.8.2012: Corrections to authentication and installation. Added “references”.
22.8.2012: Updates to revert command

Subversion version control

Subversion is a full-featured software version and revision control system. It is a centralized system (unlike Git that is a distributed version control system) that allows for multiple people to collaborate on a single project. Subversion makes it possible to merge the contributions of multiple persons into one single project and provides means for resolving possible conflicts between files. It keeps the different versions of the project (based on revision number that is increased with each commit) and provides the most recent copy (or a specific revision if requested) of files when a person updates the local copy (or does a full checkout).

A full book about Subversion usage is available at http://svnbook.red-bean.com/.

Installing Subversion

Here are some instructions for installing Subversion client tools. Currently instructions are for Debian based Linux distributions.

Linux (Debian based)

The following tutorial explains the usage of commandline svn command that in Linux comes in subversion package, e.g. in Debian based systems, do (as root)

apt-get install subversion libsvn1

For graphical interface that integrates into gedit and nautilus (also thunar) file manager there is RabbitVCS, an “easier” version control system that supports Git in addition to SVN. Full installation in Debian based systems can be done with (as root)

apt-get install rabbitvcs-core rabbitvcs-gedit

Nautilus extension:

apt-get install rabbitvcs-nautilus

Thunar extension (in Ubuntu, does not exist in Debian yet)

apt-get install rabbitvcs-thunar

Authentication

Subversion user username and password combination for user identification and authorization.

When a repository is contacted for the first time on a computer a password will be asked and is cached for future use.

If the login name of the current computer is different then the username will have to be passed as a argument, e.g., to checkout command

svn checkout https://path.to/repository/project --username myusername

Some installations of subversion do store the password in plaintext. In order to change this to use gnome-keyring or kwallet (KDE), change the line in $HOME/.subversion/config:

password-stores = gnome-keyring,kwallet

Subversion uses either one that is available (if you use gnome you can just use gnome-keyring only). Follow the instructions if you haven't used it before.

Commands

The most useful commands:

svn checkout <url> <path>
svn update <path>
svn add <path>
svn status <path>
svn commit <path>
svn diff 
svn revert <path>
svn log
svn help <command>

Details:

  • <url> = repository url
  • <path> = local file system path
  • <command> = svn command without parameters

Note that these are the long names for the commands, most of them have an abbreviated versions available. These can be seen by using command:

svn help

Get project files from repository (CHECKOUT)

The command

 svn checkout https://path.to/repository/codeproject /home/user/projects/

retrieves the newest version of the project in repository https://path.to/repository/ into current folder if the latter argument is not given. If the path is provided then the retrieved project is put into that folder.

In this example the checked out project codeproject and its contents including subfolders would be located under /home/user/projects/codeproject. If the codeproject would contain a file called code.c and a subfolder doc that contains a README file, after checkout the folder would look like (using find in /home/user/projects):

.
./codeproject
./codeproject/code.c
./codeproject/doc
./codeproject/doc/README

Do this when you are getting an existing project out of repository for viewing or editing.

To view all other options for this command, type

svn help checkout

Get newest version of contents of a project (UPDATE)

Once you have checked out a project from the repository you can check for newest version of the project using command

svn update /home/user/projects/codeproject

that will request newest files from the repository. If the path is not given the project in the current folder will be updated. E.g. running

svn update

in /home/user/projects/codeproject would update the files in the project codeproject.

This does not overwrite changes you have made to files in this project unless the elsewhere committed changes in the remote copy affect the file you have modified in the project. This situation would result in a conflict between the files. Now, conflict resolution might be tricky and when there is a conflict the local copy cannot be committed to repository. While doing the update the SVN will ask from the user what to do with the conflict. For more information about resolving conflicts see Resolve Any Conflicts chapter in Version Control with Subversion. Or if the changes are little revert the file into the state it was in the current revision.

Insert files or folders into project in the repository (ADD)

With command

svn add /home/user/projects/codeproject/header.h

you can add a file (or folders) under the version control of the project codeproject. This means that the files added are to be scheduled to be committed into the project in the next commit. I.e. this command will not make the changes into the remote copy, it just adds the files/folders under version control.

You can also add multiple files simultaneously, e.g. run in /home/user/projects/codeproject command

svn add code2.c data/ data/datafile.dat

and the files code2.c, data/datafile.dat and folder data will be tracked by SVN.

To create a folder into project you can also use command

svn mkdir directory

while inside the project folder (otherwise give the full path). Note that this command creates the project and adds it into version control. Other file manipulation commands that operate in similar fashion:

# Copy from <srcpath> to <destpath>
svn cp <srcpath> <destpath>
 
# Remove file/directory (the path is scheduled to be deleted in the next commit)
svn rm <path>
 
# Move <srcpath> to <destpath>
svn mv <srcpath> <destpath>

Check what files are changed in the project (STATUS)

The command

svn status /home/user/projects/codeproject

will show the status differences between local and remote copy. It is useful to check this before commit so the commit messages can be made more informative by telling what has been changed and where.

Some common codes:

  • A - Added
  • C - Conflicted
  • D - Deleted
  • M - Modified
  • ? - Item is not under version control
  • ! - Item is missing (deleted with external command)

Make changes to remote copy (COMMIT)

When you are ready to make changes into the project use the command

 svn commit /home/user/projects/codeproject

which will make the changes but first it will prompt for a commit message by opening up the default terminal editor set in the system. To add the commit message from command line, use additional parameter -m “message”, e.g. run in /home/user/projects/codeproject following command

 svn commit -m "My first commit"

that makes the changes to the project and creates a new commit with increased commit number containing the commit text “My first commit”.

Check the differences between the working copy and the remote copy (DIFF)

When you have made some changes to the files of the project you can use command

svn diff

to see all changes in the project. Or if a path to, e.g. a file is given the changes made to that file are presented. The removal of a line is marked with - sign and addition with + sign.

Undo the changes in the local copy (REVERT)

The command

svn revert <path>

would revert the given file into original state in the current revision of the project.

Using -R handle (recursive) with the command (note the dot - current path!)

svn revert . -R

would undo the local edits to the project if ran in the project folder /home/user/projects/codeproject.

Project history (LOG)

To view previous commits made to the project you can use command

# View all commit messages
svn log
 
# View commits made to certain file
svn log <path>

Help me out with this command (HELP)

Use help command to get further information about specific command, use e.g.

svn help checkout

to get details about the checkout command including the possible parameters that can be given.


This tutorial was written using a SVN guide in Finnish (© Lauri Kyttälä & Uolevi Nikula) for course ct60a0210 Käytännön Ohjelmointi, help pages of the subversion command line tool and the Version Control with Subversion online book.

© Jussi Laakkonen, proofreading by Tommi Kähkönen