Introduction to subversion

Remember the version of your website or application that worked? Just before you tried to add that new feature?

Enter version control. Subversion is an excellent version control system that allows you to roll back to earlier versions of an application and even share the code among different developers.


As already outlined, subversion keeps versions, or 'snapshots', of your website during development. You can then revert to an older version (snapshot) if the path you are taking just isn't working.

Have your website serve a fully functioning version of your application while you happily extend it in the background. When the updated and extended version works, simply have your website serve that snapshot with no hassle for your users.

I highly recommend the Version Control with Subversion book. It's free and on-line. I can't possibly go into as much detail as the book but I'll take you through the basics.

Installation

For this article I am using Debian Etch which has version 1.4.2 available. Ubuntu LTS has version 1.3.1 and other distributions have different versions. The latest and greatest version (at the time of writing) is 1.4.5 and is available from source from the subversion website.

Let's get stuck in and install subversion.

sudo aptitude install subversion

That's it for the installation.

Create a repository

Let's create a repository. I'm going to create a folder named 'repository' in my home directory. It can, of course, be named whatever you like and be located wherever you like:

cd ~
mkdir repository

If you have a look inside the repository folder, there is nothing there:

ls repository
...

Let's create the skeleton structure subversion uses to control repositories:

svnadmin create /home/demo/repository

Take a look now:

ls repository/
conf/  dav/  db/  format  hooks/  locks/  README.txt

Don't change anything in the repository folder. We'll learn how to add files and projects shortly.

Our first project

To import 'something' to our subversion repository and begin version control, that 'something' has to exist.

You can import whatever you like (there are a few exceptions, but not many). The most popular use for subversion is to manage projects, from small websites to very large, multi developer systems.

Let's create a temporary folder for our project. We'll call it 'project1'

mkdir project1

Now start the project by creating a text file:

touch project1/hello.txt

Initial import

I know that project1 is not incredibly realistic; you could have created a rails skeleton or the base of your php website or whatever you wanted, the point is to have something to import to the subversion system.

The recommended layout for a subversion project includes three folders called branches, tags and trunk. I'm not going to go into branches and tags here but concentrate on the 'trunk' of your project. Then name is very apt - think of it as the backbone of your project - this is where the main folders and files are placed.

To import project1, issue the command:

svn import /home/demo/project1/ file:///home/demo/repository/project1/trunk -m "Initial import of project1"

A couple of things to notice include the order of the command (source folder followed by destination) and the '-m' which is short for 'message'.

When you import a version of your project, always add a message describing what the import is. I can assure you that in a week, never mind a month, you will have no idea what version 127 was if you do not include a message.

The output of that command is:

Adding         /home/demo/project1/hello.txt

Committed revision 1.

delete original

Now we delete the original project1 as we don't need it because we've imported it into the version control system.

So, delete the original:

rm -rf project1/

Check out a repository

The point of subversion is to control versions of a project.

To do this we need to 'check out' the initial project (this will be version 1). Once done, we can then adjust the project (add files, change files, etc) and at various points 'check in', or commit, any changes we have made. So the next 'commit' would make version 2 of the project and so on.

Assuming you are working on the same machine as your subversion repository (we'll talk about remote manipulation in later articles), create a 'work' directory and check-out version 1 of project1:

mkdir work
cd work
svn co file:///home/demo/repository/project1/trunk project1

The output is:

A    project1/hello.txt
Checked out revision 1.

Move into your newly checked-out project1 and have a look:

cd project1
ls
...
hello.txt

Look familiar? It's the original project1 we imported a moment ago.

Adding Changes

Let's make a small change to project1 and add a folder and file (remember we changed directory so we are now working in the project1 folder):

mkdir goodbye
touch goodbye/goodbye.txt

We need to add this change to subversion. This does not commit the change to a new version: it simply tells subversion there is a new file (or folder, etc) that has been added to the project and to include them when the next commit command is given:

svn add goodbye

The output will show that the directory and contents of 'goodbye' have been added:

A         goodbye
A         goodbye/goodbye.txt

Committing Changes

To actually commit this momentous change to project1 (thus creating version 2) issue the following:

svn commit -m "Added goodbye section in accordance with milestone 1"

The output shows what is happening:

Adding         goodbye
Adding         goodbye/goodbye.txt
Transmitting file data .
Committed revision 2.

Deleting files

If you want to delete files or folders from the project, use the same syntax as shown above for 'add' but use 'delete' instead:

svn delete goodbye

The output shows:

D         goodbye/goodbye.txt
D         goodbye

Again, this has not committed the changes. It has simply informed subversion that when there is a 'commit' command, to delete those files and folders.

Committing Changes

So to actually commit the recent changes and create a new revision (version):

svn commit -m "Deleted goodbye section"

which produces:

Deleting       goodbye

Committed revision 3.

So now we're on version 3 of project1.

Revisions

There is a great deal more you can do with subversion and one other skill you will probably require early on is how to check-out different versions. We're on version 3 now, but let's say we also want to check out version 2.

Using the same procedure as before and create a directory to work in. This time, when checking out project1, use the '-r' option indicating the version you want to use:

cd ~/work
mkdir project1-older
svn co -r 2 file:///home/demo/repository/project1/trunk project1-older

This will checkout revision (version) 2 of project1 to the project1-older folder.

Summary

Although only an introduction, a fair amount has been covered here. You will get used to these basics very quickly and want more functionality within a very short time.

The next article will concentrate on serving the repository with svnserve so you can check out the project to your local workstation.

PickledOnion

Article Comments:

Melvin Ram commented Sun Jan 13 01:47:18 UTC 2008:

Good start. Went through it without a hicup. Hopefully I get this subversioning thing down soon. Thanks for all the awesome help.

Kenny Pate commented Thu Jun 05 19:15:32 UTC 2008:

I realize it's probably beyond the scope of this document, but a quick FAQ on moving a SVN repository from somewhere else to the slice would be handy. Thanks!

Daniel Wood commented Mon Jun 16 19:51:07 UTC 2008:

This is a great reference! Maybe it would be helpful to add a CVS reference as well?

Antonio commented Tue Jul 15 00:25:46 UTC 2008:

This tutorial is great for beginning. I've finally got into the svn worflow. Thanks!

Ilian Andreev commented Wed Sep 24 14:35:44 UTC 2008:

Yes really great and clean introductory tutorial! :) Thank you ;)

Baruch commented Fri Dec 05 04:14:53 UTC 2008:

For some reason, using svn keeps giving me segmentation faults.

Christ commented Thu Jan 22 12:26:58 UTC 2009:

found your subversion howtos vio google and --- i always knew it could be easy but never got it running at all. with your great help my repository is running now. many many thanks. would love to order a slice but need germany based servers (seo). cheers chris

KFCSpike commented Sun Mar 01 12:14:25 UTC 2009:

If you use SVN to update a website then there is a security issue unless you block access to .svn folders. A request to www.example.com/.svn/entries will show file-paths and usernames unless blocked.

To block in apache, put these lines into apache2.conf:

<locationmatch> Order allow,deny Deny from all </locationmatch>

donarb commented Fri Mar 13 01:02:53 UTC 2009:

Actually, if you are pulling your website out of svn into your server's document root, you should not be using the checkout command, use export instead. Then svn won't put all those .svn folders everywhere. Not only can it be a security risk, but some of those folders can be quite hefty, sometimes doubling or tripling your storage space.

Syed Mazhar Hasan commented Wed Jul 22 07:06:37 UTC 2009:

Gr8 point donarb, that was handy ;)

Suits commented Tue Jan 12 19:23:00 UTC 2010:

Thanks for the help.

Joel commented Tue Feb 23 09:30:52 UTC 2010:

Very nice, terse article. I do have one question: does it matter which user creates and thus owns the repository folder? What about the user that runs svnadmin create?

I guess I'm asking that will permissions be an issue because I'm aiming for a multi-project multi-user environment with private and public projects.

Svenson commented Thu May 20 06:26:52 UTC 2010:

Vielen Dank

Kable commented Fri Nov 04 02:32:56 UTC 2011:

very good and still helpful. This tutorial is very easy to understand.

peter commented Mon Nov 21 08:25:08 UTC 2011:

thanks very much, very good tutorial.

here commented Sat Dec 03 15:10:24 UTC 2011:

Thank you for the good tips

Peter

Mopped commented Mon Feb 13 11:57:53 UTC 2012:

Does it also works with debian?

Sommerreifen commented Sat Feb 18 20:12:36 UTC 2012:

Nice article!

Thank you!

jak poderwac dziewczyne commented Mon Jul 02 23:22:25 UTC 2012:

Thanks for this tutorial, it helped me a lot. Have a great day

Skumar commented Tue Jul 31 14:15:29 UTC 2012:

A Great article for subversion beginners. I can work with subversion now following this article. Thanks to Slicehost.

Doris commented Sun Oct 07 11:56:44 UTC 2012:

Goog articule. The topic is not easy for beginners, but the articule helps a lot.

Duft Kerze commented Thu Nov 01 22:56:51 UTC 2012:

many thanks and thanks very much, very good tutorial.

Adrian commented Tue Feb 05 16:16:40 UTC 2013:

Vielen Dank

Sehr hilfreich

Lipozene Reviews commented Tue Feb 12 14:40:43 UTC 2013:

Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.

Alfred commented Sun Mar 24 15:35:27 UTC 2013:

Terrific article! That is the kind of info that are supposed to be shared across the internet. Shame on the seek engines for now not positioning this put up higher! Come on over and seek advice from my site . Thanks =)

Velma commented Tue Mar 26 17:19:45 UTC 2013:

I blog often and I genuinely thank you for your content. Your article has really peaked my interest. I am going to take a note of your site and keep checking for new information about once a week. I subscribed to your Feed as well.

vip loan shop commented Sun Mar 31 23:46:03 UTC 2013:

On the commercial business person, cracking open a fresh services could be loaves of bread but butter of these time, picking a quality day care series entails the difference from a highly effective establishment this is. preschool franchise

test2 commented Mon Apr 08 19:18:27 UTC 2013:

I love your website. Well done good sir. Bravo!

toshiba coupon code commented Sun May 05 02:18:12 UTC 2013:

I figured out that the more I surf the internet, the more intelligent I get. You might desire to add it to your site

golf channel tiger woods bulging commented Sun May 05 03:50:14 UTC 2013:

Hello my family member! I wish to say that this post is amazing, great written and come with almost all vital infos. I'd like to see more posts like this .

cialis bestellen commented Sun May 05 11:11:20 UTC 2013:

Seite gleichfalls eine kleine Häutschramme.

cialis bestellen commented Sun May 05 11:12:40 UTC 2013:

Seite gleichfalls eine kleine Häutschramme.

cialis bestellen commented Sun May 05 11:13:10 UTC 2013:

Seite gleichfalls eine kleine Häutschramme.

cialis bestellen commented Sun May 05 11:14:03 UTC 2013:

Seite gleichfalls eine kleine Häutschramme.

viagra generico commented Sun May 05 11:21:09 UTC 2013:

acido cloridrico concentrato.

viagra pour homme commented Wed May 08 21:01:49 UTC 2013:

et Nycod soyent ranvoye et dud.

cialis 20 mg commented Wed May 08 21:03:49 UTC 2013:

y con cuatro barbas y cabelleras y cuatro

viagra ersatz commented Wed May 08 21:04:36 UTC 2013:

Dem Gewerksmann ist es für seinen Betrieb

cialis lilly commented Wed May 08 21:07:19 UTC 2013:

Francisco Miguel Noisen babia sido sangrado del.

viagra commented Sat May 11 21:00:15 UTC 2013:

in contrasto con quanto consentito dalla

cialis original commented Sat May 11 21:00:56 UTC 2013:

und wird demjenigen ähnlich.

cialis lilly commented Sat May 11 21:05:56 UTC 2013:

le neutralise directement.

fisioterapia roma monte mario commented Tue May 21 06:38:12 UTC 2013:

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.

DWI Attorney Houston commented Fri May 24 07:35:12 UTC 2013:

I was wondering if You Could write a little more on this subject? I'd be very gratified if You Could elaborate a little bit more.

Share It commented Sat Jun 08 06:23:52 UTC 2013:

Hi if you are pulling your website out of svn into your server's document root, you should not be using the checkout command, use export instead. Then svn won't put all those .svn folders everywhere. Not only can it be a security risk, but some of those folders can be quite hefty, sometimes doubling or tripling your storage space.

Share It commented Sat Jun 08 06:25:24 UTC 2013:

Hi if you are pulling your website out of svn into your server's document root, you should not be using the checkout command, use export instead. Then svn won't put all those .svn folders everywhere. Not only can it be a security risk, but some of those folders can be quite hefty, sometimes doubling or tripling your storage space.

VPN service benefits commented Sun Jun 16 07:03:48 UTC 2013:

And it comes from saying no to 1,000 things to make sure we don't get on the wrong track or try to do too much. We're always thinking about new markets we could enter, but it's only by saying no that you can concentrate on the things that are really important.

VPN service benefits commented Sun Jun 16 07:06:22 UTC 2013:

And it comes from saying no to 1,000 things to make sure we don't get on the wrong track or try to do too much. We're always thinking about new markets we could enter, but it's only by saying no that you can concentrate on the things that are really important.

VPN service benefits commented Sun Jun 16 07:06:53 UTC 2013:

And it comes from saying no to 1,000 things to make sure we don't get on the wrong track or try to do too much. We're always thinking about new markets we could enter, but it's only by saying no that you can concentrate on the things that are really important.

college paper editing services commented Fri Jun 28 07:43:54 UTC 2013:

Good information here.I really enjoy reading them every day.I’ve learned a lot from them.It is very helpful and very informative and I really learned a lot from it.Thanks so much for sharing this information.

Ralph Lauren Polo commented Wed Jul 17 21:51:42 UTC 2013:

http://www.sharkindo.com/Ralph Lauren Outlet

bra set commented Thu Aug 15 02:11:52 UTC 2013:

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.

bra set commented Thu Aug 15 02:12:33 UTC 2013:

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)