Introduction to Subversion via CentOS Command Line

From Acenet Knowledgebase
Revision as of 13:20, 9 October 2012 by Docs admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What is Subversion?

Subversion is a software version control system, allowing users to keep track of when and why changes occur to open source code. Code is stored in a directory structure called a repository. Changes to files and directories within a subversion repository are committed, resulting in a new version of the software which can be easily checked out by other users implementing that repository.

Subversion is available in many Linux distros (as well as Windows). This article focuses on using subversion via SSH in CentOS.

The subversion homepage is:

http://subversion.apache.org/

This basic tutorial covers installing subversion, creating a repository, importing projects, checking out your repository, and committing revisions to the repository.

Installation

Here is the command you will want to run via SSH when logged in as root:

yum install subversion

Creating a Repository

Change your current directory to where you want to create your repository. In this example, we'll use /home/repo/ as our working repository directory. This is the directory that subversion will use to store information about your projects.

The 'svnadmin' command is used to create the repository. In the following example, 'mysvn' is the name of our repository. You can name your repository whatever you would like.

cd /home/repo
svnadmin create mysvn

Importing Projects

Projects are imported and managed within the repository created above.

Importing a project requires a directory within your repository. Let's make that directory now using the 'svn' command. You should replace the path in the below command with the actual path to your repository and new project name.

svn mkdir file:///home/repo/mysvn/myproject

Subversion will open your Operating System's default text editor, where you will log an explanation of what you are doing, what changes you're making, etc. After completing your log entry, save and exit the editor.

/home/repo/mysvn/myproject has not yet been created in your Operating System's directory structure. It is only available in your repository. This directory will be created after using the checkout command described below.

Import project files using the svn import command:

svn import file:///home/repo/mysvn/myproject

Files in your project are imported into the 'myproject' directory within your repository.

Checkout and Commit

To make revisions to your project files, a working copy of your project must be checked out of the repository. For this, we use 'svn checkout':

svn checkout file:///home/repo/mysvn

The repository and all revisions are now checked out. A new directory containing your project's files is now available in your OS directory structure. To view them, simply change to your project's directory:

cd /home/repo/mysvn/myproject

You can now make revisions to your project's files. When you are finished, and you're ready to store your new revision into your repositoiry, run 'svn commit' from your project's directory:

svn commit

Subversion will again open your Operating System's default text editor where an explanation of your revision are logged. Save and exit the text editor when you are finished.

Your revision is now committed to your repository. Other users can now implement the revisions that you made to your software.