March 21, 2019

Version Control For Beginners: Getting Started With Subversion

Setting Up a Repository

  • February 9, 2009
  • By Juliet Kemp

Juliet Kemp
Subversion is a version control system: It keeps a record of changes over the lifetime of a file, allowing you to revert to an earlier version at will. It's particularly useful for code projects, but it can handle, and be useful for, pretty much any type of file (e.g., for tutorials!). It's available as a package for most Linux distros, or as source from the web site.

Setting Up a Repository

svnadmin create /usr/share/svn/repos

Alt text
Creating a Repository

The first step in using Subversion is to set up a repository. This is your storage space ��� you don't work on files within it. Instead, you check files out into a working space to make changes, and then check them back in to record your changes.

To set up a new repository, simply type:(Note that /usr/share/svn/ must exist already). Within the repository, you can have multiple projects, stored as multiple directories.

Importing Existing Files Into a Repository

When starting a new project, you'll probably want to import existing files into it. For a project currently in /home/user/myproject:

cd /home/user
svn import myproject file:///usr/share/svn/repos/
           myproject -m "Initial import"
(This will take a little while if you have many files.) The -m switch attaches the log message. If you leave this out you'll be prompted for a message.

Your current working copy of these files ��� the directory you imported them from ��� is not a Subversion-controlled copy. Before you do any more work on these files, you must check them back out of Subversion, using the command:

svn checkout file:///usr/share/svn/repos/myproject
This will create a myproject subdirectory in your current directory and check out all the files from that project into it.

Working With Files

You now have your repository and your working directory, so you can work with files and check any changes back into Subversion. Let's start by creating a new file, newfile.txt. Once you've created the file in your working directory, add it to the repository with:

Alt text
Subversion in Action
svn add newfile.txt
This command, however, doesn't actually finalize the add ��� it just schedules it to be added next time you do a commit. To actually commit the file to the repository, type:
svn commit
You'll be asked to enter a logfile message ��� make sure you fill in something that will make sense to you later! (To avoid the prompt, use the -m "logfile message" switch.) The file, and any other updates, will be committed to the repository.

Most Popular LinuxPlanet Stories