Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Introduction to Subversion, an Open Source Version Control Tool

  • Print
  • + Share This
Subversion is a free, open-source software package for tracking changes made during software development across versions. This chapter will walk you through the basic use of Subversion, from creating a new repository, all the way through to more complex features such as creating and merging a branch.
This chapter is from the book

In this chapter, I will walk you through the basic use of Subversion, from creating a new repository, all the way through to more complex features such as creating and merging a branch.

If you are like me, you learn best by actually sitting down at a computer and getting your feet wet. To allow you to do that, all of the examples in this chapter build on each other, one right after the other, starting with a simple Hello World project. All of the examples in this chapter assume that you are in a UNIX-like environment, such as Linux or Mac OS X. For the most part, they will all work if you are running in a Windows environment, with a few minor changes, such as turning forward slashes (/) in path names into backslashes (\).

We'll start the project with two files, which make up our example project. The first file is the source for our Hello World program, hello.c:

#include <stdio.h>

int main(int argc, char** argv)
{
    printf("Hello World!!\n");

    return 0;
}

The second file is a makefile, which could be used with the make program to compile our fabulous application. The file is named, appropriately, Makefile:

all: hello.c
    gcc hello.c -o hello

4.1 Creating the Repository

Subversion stores files in a repository database (which is Berkeley DB by default, but version 1.1 also supports FSFS). So, the first thing to do is create a new repository where we can store Hello World. This is done using the svnadmin program, which is used for most server-side administrative tasks when using Subversion. The repository is created with the svnadmin create command. First, though, you will want to create a directory in your home directory, where you can store the repository (you'll see later why creating it directly in your home directory isn't a good idea). If you were creating a repository to use on a server, for production use, you would probably want to place it somewhere other than your home directory, such as /srv/ or /var/.

In the following example, bill should be replaced with your username on the machine where you are creating the repository. Similarly, in all future examples where you see my username, bill, you should replace it with your own username.

$ svnadmin create --fs-type fsfs /home/bill/my_repository

This creates an empty repository named my_repository in your home directory, using the filesystem-based FSFS repository backend. By choosing FSFS instead of the default Berkeley DB backend, you don't need to worry about repository wedging, which can happen if Berkeley DB is interrupted. Although wedging is not fatal to repositories, it will leave your repository in a temporarily inaccessible state, which requires the Berkeley DB recovery process to be run in order to clear the wedge.

In most situations, you will want to create a repository on a server, and access it through HTTP/HTTPS, or the Subversion server svnserve. For simplicity's sake, though, we'll take advantage of Subversion's capability to communicate directly with a repository on the local machine, using a local directory path, for all of the examples in this chapter.

After you've run the create command, you can look in your home directory, and you will see that Subversion has created a directory named my_repository. This contains the repository database. In general, you won't directly edit any files in this directory. Instead, you will interact with it through Subversion's svn command. If you look inside this directory, you can see that there are a bunch of files and directories, but there is little reason for you to worry about what they are for at this point. In Chapter 11, "The Joy of Automation," you will learn how you can edit some of the files in your repository to customize Subversion's behavior.

$ ls /home/bill/my_repository/
README.txt conf/ dav/ db/ format hooks/ locks/
  • + Share This
  • 🔖 Save To Your Account