Subversion - A Quick Tutorial
I don't know how I managed to survive for years without some sort of version control for my personal projects. First, I used to manually make backup copies of my project directory in case I wanted to revert back or compare revisions. Later, I relied on Eclipse for a very basic version control system. Eclipse stores copies of project files after every save, and lets you compare revisions. Next, I decided to write a script that made backup copies of my projects directory, and archived them according to date/time.
Finally, and given that I have been using CVS to contribute to various Open Source projects for a long time, I saw the light and decided to utilize a version control system for my own projects.
I have been hearing about Subversion for a while, but never had the chance to read more on or try it out. So I decided to experiment with it instead of going directly with CVS. First, it started as "trying something new" but later I realized Subversion has new features that cover many limitations of CVS. I'm no guru of either, but here's what I found:
- Subversion tracks structure of folders. CVS doesn't have the concept of folders.
- Subversion has a global revision number for the whole repository. CVS tracks each file individually. A commit that represents one logical change to the project code may change a group of files; in Subversion, this commit will have one revision number instead of separate revision numbers for every changed file in CVS.
- Subversion commands are very similar to CVS. It's very easy to switch for CVS users. Most of the time it's a matter of replacing
cvswithsvn.
Again, I don't know all ins and outs of CVS or Subversion, if I'm missing anything, please correct me!
It took me less than an hour to experiment with Subversion, learn it, and import my projects to it. So I decided to write a quick tutorial for those who:
- Are already familiar with version control systems (like CVS).
- Haven't used any for controlling their local projects.
- Would like to try Subversion.
If this is not your case, I point you to "Version Control with Subversion" where I started reading about Subversion.
Read on for the quick tutorial.
Installation
The first step for using Subversion is installing it. This depends on your system. For us, Gentoo users, we can get Subversion going with one command:
# emerge subversion
Subversion has packages for many systems, Linux (Gentoo, Debian, Fedora, ...), Mac OS X, FreeBSD, Windows, ...
Creating The Repository
The first Subversion tool we will use is svnadmin. This tool is for administration tasks, like creating repositories, making backup dumps, and the like. To create a repository, open the command line, change the current directory to where you want to create it, and run svnadmin:
$ cd /home/ayman $ svnadmin create svn
/home/ayman)
I called my repository svn. You can call it whatever you like. Subversion uses this directory to store information about your projects, like file revisions. You won't need to directly deal with this directory, so I suggest keeping it in a safe place and not tinkering with its contents unless you know what you're doing.
Importing Projects
Now that we have a repository, we will use the svn tool to import and manage projects. To import a project, first create a directory for it in your repository. To do so run svn mkdir:
$ svn mkdir file:///home/ayman/svn/myproj
/home/ayman/svn/myproj with the actual path to your repository and the new project name)
Subversion will open your default text editor and ask you to enter a log message. Enter an explanation of what you're doing, save, and exit the editor.
Next, it's time to import project files. Change the current directory to the project's directory, and run svn import:
$ cd /home/ayman/[...]/myproj $ svn import file:///home/ayman/svn/myproj
/home/ayman/[...]/myproj to the newly-created myproj directory in your repository)
Check out, Modify, Commit
As I said, the repository is stored in the svn directory which you won't deal with. To work on your files, first you need to check a working copy out of the repository. To do so, use svn checkout:
$ svn checkout file:///home/ayman/svn
A new directory named myproj will be created containing your project files. You can work and modify them. Once you're done and you want to store the new revision in your repository, run svn commit in the checked-out myproj directory:
$ svn commit
Subversion will open your default editor asking for a log message. Again, enter an explanation, save, and exit.
Working with Revisions
Now let's make real use of Subversion. While working with revisions, you can:
Check Status
$ svn status [filename]
Compare different Revisions
$ svn compare -r R1:R2 [filename]
Revert Local Edits
$ svn revert [filename]
Revert to Previous Revisions
$ svn update -r R
[filename] is optional; you can run the previous commands on the current directory if you omit it.
A Final Word
This is a very quick start for using Subversion to control local projects. For extended help on commands, you can always use svn help [command] to get a help message on [command], for example:
svn help import
This will give a lengthy explanation on
svn import.
In addition, check out "Version Control with Subversion" for detailed information.
Good luck, and happy subversion'ing!













JVA (not verified) | Good for you | Fri, 2006/01/13 - 4:23pm
Version Control, is an essential tool in software engineering, so good for you to switch into this organized programming world, no lost versions anymore, no overwritten version either.
I use CVS, i've heard that SVN is better, but CVS is more popular "as far as i know", and i started with CVS first. I do basic management of my source, no branches and stuff, so i'll stick to CVS.
Anyway, nice tutorial.
nart (not verified) | btw, its also nice to use | Tue, 2006/02/14 - 1:39pm
btw, its also nice to use Trac (http://www.edgewall.com/trac/) with svn for collaborative projects.
john (not verified) | subversion | Fri, 2009/02/13 - 2:35am
Great choice by picking Subversion. I use Subversion myself, and the reason why I like it the most is because Subversion tracks structure of folders. In my opinion, it is the best version control system out there. Good luck with it, Ayman.
----------
supreme buy - keyword elite - seo elite - water4gas - fat loss 4 idiots - rocket spanish
Dandor (not verified) | revision numbers | Thu, 2006/03/16 - 2:56am
It's a nice little tutorial. Just one remark. I think it's a better idea to create repositories on per project basis, this way you will have separate numbering for different projects. Anyway it's a very useful summary.
Pelle (not verified) | Repositories per project? | Fri, 2008/09/12 - 12:05pm
Dear all,
I'm only just getting started with version control and I chose subversion with TortoiseSVN for my needs.
I had thought about doing repositories per project, too, but somehow I feel like this is not intended.
Does anyone know where to start reading about repository-layout and whether it's a good or bad idea to do this on a per-project approach or rather do repositories for a single group of developers or whatever?
Any help on this would be greatly appreciated!
Thanks,
Pelle.
maram (not verified) | the tag <cite></cite> not work | Sun, 2006/08/20 - 2:21pm
I'm use firefox.
Ayman | Fixed, thanks, I installed a | Sun, 2006/08/20 - 2:56pm
Fixed, thanks, I installed a new filter that broke this article.
prasad iyer (not verified) | Very nice article | Sat, 2008/08/30 - 9:04pm
Very well written. I am setting up my repository now.
Thanks for the help
Aamod (not verified) | Thanks | Fri, 2008/10/24 - 3:44pm
Very neatly written and useful for lazy people like me. Using svn after just reading this single page.
Thanks ;-)
Ahmed El Gamil (not verified) | Thanks :) | Mon, 2008/11/17 - 8:17pm
Thanks Ayman for this simple yet powerful tutorial
DJ (not verified) | nice | Wed, 2009/02/11 - 12:28am
Thanks for the simple version of setting this up.
Abdullah (not verified) | Well written totorial. | Mon, 2009/02/16 - 1:22pm
Well written totorial. Thanks
al (not verified) | i have installed Subversion | Tue, 2009/03/03 - 12:31pm
i have installed Subversion in Ubuntu but how do i access it from WinXp.
Alexander (not verified) | THX | Fri, 2010/01/08 - 6:47pm
At first, a very sincere THANK YOU Ayman!one-eleven!
I got subversion up und running in a few minutes.
Al: If you want to access SVN via Studio .net (2005 and Successors) you may be interested in Ankh svn. It works very fine for me.
You may need to tune your authz and passwd files in the svn Root:
http://groups.google.de/group/Subversion-SVN/browse_thread/thread/ebd14b999b67e458
Matthew Frazier (not verified) | Very good tutorial | Fri, 2009/03/20 - 4:54pm
Thanks for putting this together. A very clean, concise guide to setting up a simple versioning system. I was up and running in under 15 minutes.
Tom (not verified) | re | Fri, 2009/03/27 - 9:10pm
A tutorial walkthrough of Subversion, from creating your first repository to basic branching and merging. *A detailed look at the most important Subversion client commands, as well as properties, user configuration, and integration with a variety of external tools. *A guide to repository administration and organization, including repository security and migration from another version control system. *An in-depth look at automation in Subversion, including using hook scripts, metadata, and the Subversion API, plus example scripts. *Case studies that examine both archetypal and real-world projects and their use of Subversion. *A Subversion command reference for fast access to essential technical information. *Details on Subversion's many advanced features, such as its Apache-integrated WebDAV server and database file storage system. Whether you are an administrator, project manager, or software developer, Subversion Version Control will show you how to realize the full potential of Subversion.
Tom Green
Gold Price Blog
Personal finance advice
Insurance blog
Anonymous (not verified) | Command prompt sucks | Tue, 2009/04/21 - 3:18am
Don't know why anyone would want to use a command prompt and not the context menu (assuming you're using windows) to do all this above. Same with using Visual SVN Server. Command prompt is sooo tedious.
GeekyGrad (not verified) | Great tutorial | Thu, 2009/04/30 - 8:25pm
This is a great piece of work - I linked to it in my article on using Subversion for LaTeX files.
Igor Grinkin (not verified) | Compare different Revisions | Mon, 2009/07/06 - 5:30pm
I'm using:
Subversion command-line client, version 1.4.6svn compare -r R1:R2 [filename]did not work for me :(
Unknown command: 'compare'svn diff -r 1:2 filenameworked fine.
I'd also add
svn log filenameIt shows you the revision numbers
Thanks for the tutorial!
Anonymous (not verified) | Great | Wed, 2009/08/19 - 5:44pm
I'd give you 3 thumbs up if I could...
Ali (not verified) | Well done | Mon, 2009/09/14 - 1:10am
Thanks for this short and to the point article...
Many thanks,
Binary Soldier (not verified) | Nice guide | Fri, 2009/09/25 - 12:11am
Having just installed Subversion today it's great to find such a useful quick start guide.
Version checking is something new to me, and since SVN seems to be the industry standard, I thought I should get to grips with it as soon as possible.
Thanks for sharing!
Chris (not verified) | Thanks | Mon, 2009/09/28 - 5:45am
Just wanted to say thanks for this... I've been tearing my hair out trying to get this working and set up with my svn client; so much of the documentation/forum-responses have been useless... very nicely done.
For any other folks using this approach to set up the repo, and are looking to use Tortoise, or Versions, or some other GUI to access it, I was getting hung up on finding the right URL to direct the client to... turns out it was ssh login plus the absolute path from the server root down to the svn project directory
e.g., svn+ssh://username@testsite.com/home/domains/xyz.com/html/svn/my_proj
ge (not verified) | Waht is the proper SVN connection URL to access a remote reposit | Fri, 2009/10/09 - 6:05pm
Thanks for posting this article.
I'm trying to learn SVN and am having trouble connecting to a remote SVN server I've recently setup on a Windows machine.
I've created a repository on the server with the following full path: C:\svn\test_repository.
When I try to create a project directory in the repository using
"svn mkdir http://mySvnServer.myDomain/svn/test_repository/new_project" It returns an http "200 OK" message but no directory ever gets created on the server.
If I try to do an initial import of a project I get a similar result.
"svn import http://mysvnserver.myDomain/c$/test_repository" returns the message "svn: OPTIONS of 'http://mysvnserver.myDomain/c$/svn/test_repository': 200 OK (http://mysvnserver.myDomain)
which appears to be OK, except that when I go to the server and check to see if the project directory was created, I find that it has not.
Darren (not verified) | Thank You | Sun, 2010/01/03 - 5:36am
Thanks so much for the tutorial, it clarified some of the conceptions I had about this neat little program.
kobedi (not verified) | Tutorial | Wed, 2010/01/06 - 7:14am
Thank you very much...Good summary.
Yatko (not verified) | Some problems I encountered | Tue, 2010/02/16 - 2:47am
Hi, and thanks for this tutorial. However I was unable to get It work:
$ svn mkdir file:///home/ayman/svn/myproj
Subversion will open your default text editor and ask you to enter a log message. Enter an explanation of what you're doing, save, and exit the editor.
It saves a .tmp file and does not create any directory
svn import file:///home/....
Creates second .tmp file ()
I gave up.... I am sure it is a great toy, but ....for insiders only.
Thank you!
Post new comment