Subversion is a versioning tool which will allow you to keep track of different versions of a project over time. This will allow you to easily revert back to an earlier version of a file or directory or to view the differences between two versions, which is especially useful to programmers and website developers. This article aims to give basic instructions on how to get started in Linux.
The first thing you will need to do after installing Subversion is to create a repository. A repository is a directory for storing data. In this example, the repository will be located at
/home/svn. The following commands will create a repository:
$ sudo mkdir /home/svn # Create the repositories directory $ sudo addgroup svn # Create the svn group $ sudo adduser $USERNAME svn # Add the current user to the svn group $ sudo chown -R $USERNAME /home/svn # Make the current user the owner of the repository $ sudo chgrp -R svn /home/svn # Make the svn group the owner of the repository $ sudo chmod -R g+rws /home/svn # Change the permissions on the repository $ svnadmin create /home/svn # Tell subversion to create the repository's files
You will then be able to import a project. The command below will copy the files from the project's directory into the repository.
The files are placed into the trunk directory to represent the latest version. This is optional, but it allows you to create a tags directory (eg.
tags/before_big_change2, etc.), which saves you remembering revision numbers and comments, and is generally good practice.
You will also have to provide a comment with every change to the repository with the
$ svn import /path/to/project/ file:///home/svn/project/trunk -m 'Initial import'
At this point, you should delete the project and then retrieve it again by using the checkout command. This will place hidden
.svn directories in each directory of the project, which Subversion uses to determine what has changed between different versions.
$ cd /path/to/project # Go to the project's folder $ cd .. # Go up one level to the parent directory $ rm -rf project # Delete the project and it's files and folders $ svn co file:///home/svn/project # Retrieve the project with Subversion's hidden data folders
You can also export the project without Subversion's data files (although then updating and committing won't work) with the command:
$ svn export file:///home/svn/project # Retrieve the project without Subversion's data files
Sometimes you may wish to clean a checkout so that it becomes the same as an export. This can be done with the following command which will recursively delete all files and folders matching
$ cd /path/to/project $ find . -name "*.svn" -print|xargs rm -rf
To allow subversion to listen to incoming connections from other computers (needed if you plan on allowing other computers to access your repository), you can use the
svnserve application, which you will want to run at every system boot. Create a new cron entry by entering the command
crontab -e and entering the following line:
@reboot svnserve -d -r /home/svn
For subversion to know who is allowed to access what, you can edit the
conf/svnserve.conf file in the repositories directory (eg.
/home/svn/conf/svnserve.conf). You can now access the project with the command:
$ svn co svn://127.0.0.1/project
It is also possible to checkout and commit to remote repositories (repositories on other machines), although you will usually have to specify a username and password (depending on the configuration):
$ svn co svn://188.8.131.52/project --username myUsername --password myPassword