Subversion on Windows quick start

I have a number of personal projects that I store in the Subversion version control system. This is my cheat sheet for how to create a new Subversion repository for a project.

Assumptions

These instructions will be most useful to you if you have the same work style as me: projects that only have one developer, the Subversion repository is on the same machine accessed as a file, you run on Windows, and you like using the command-line. If you have other needs, maybe you can adjust these instructions, maybe not.

Starting assumptions:

  1. You have Subversion installed, with the binaries on your path.
  2. You have a tree of project files in a directory called ‘c:\myproj’.

Prepare your project files

Before putting your project in Subversion, you should prepare the project a bit first.

  1. Backup your project files in case something goes wrong.
  2. Delete files that you don’t need, either because they are obsolete, or because they are generated files. For example, editor backup files, compiled binary files, or junk you just don’t want anymore.

Setting up the repository

Now we’re ready to put the project into Subversion. Here’s what you do:

  1. If you’ve never created a local Subversion repository, choose a place to put it, and make the directory:
    $ mkdir c:\svn
  2. Create a Subversion repository, using the Windows file path to the repository:
    $ svnadmin create c:\svn\myproj
  3. Import your existing project files into Subversion, using the URL address of the repository:
    $ svn import c:\myproj file:///c:/svn/myproj
    An editor will pop open to collect a comment from you. This file indicates that just c:\myproj is being added, but Subversion will pull in all of the contents of that directory too. Once you save the file, the existing files will be imported into your new repository.

Congratulations, you’ve created a Subversion repository containing your project.

Getting a working copy

Now your files are stored in Subversion, but there is no Subversion-aware copy of the files for you to work on. Make that copy by checking out your project from Subversion. You can’t checkout over your original files because Subversion will complain that an object of the same name already exists. Either delete your original files (you backed them up, right?), or checkout to a new directory:

$ rmdir/s/q c:\myproj
$ svn checkout file:///c:/svn/myproj c:\myproj

Now you have your project back where it started, but under Subversion control.

Tweaking the contents of the repository

Usually, there are files in your project directory that you don’t want stored in Subversion. These were files you may have cleaned up above. For example, Python produces compiled .pyc files. You can instruct Subversion to ignore these files, so that you don’t accidentally store them in your repository. Subversion can store properties on files and directories as well as the contents. You tell Subversion which files to ignore by setting the svn:ignore property on directories.

  1. For files that should be universally ignored, create a text file called ignore.txt. In it, list the file patterns that should be ignored, one per line:
    *.pyc
    *.obj
    *.bak
  2. Then use that file to set the svn:ignore property on all directories in your tree:
    $ svn propset -R svn:ignore . -F ignore.txt
    property 'svn:ignore' set (recursively) on '.'
  3. If certain directories should have other files ignored, you can edit the property on those directories:
    $ svn propedit svn:ignore .
    A text editor will open, with the list of ignored files. Edit the list however you want, then save the file and close the editor.
  4. The changes you’ve made to the directories now have to be committed back into your repository:
    $ svn commit -m "Ignoring ignorable files"
    Sending        .

    Committed revision 2.
    (We used the -m switch to provide a comment, avoiding the editor opening to collect one from us.)

Working

Now you work on your project. You can change files without checking them out first. The files are writable, and Subversion has its own copy so it can tell what has changed.

To add a new file to your project, create the file, then tell Subversion about it with the add command:

$ svn add a-file-I-added.txt
A         a-file-I-added.txt

See what you’ve changed with the status (or st for short) command:

$ svn st
A      a-file-I-added.txt
M      a-file-I-modified.txt
?      a-file-I-forgot-to-add.txt

Changes get committed back to the repository with the commit (or ci) command:

$ svn ci -m "Put a comment here, or an editor opens to get one."
Adding         a-file-I-added.txt
Sending        a-file-I-modified.txt

Committed revision 3.

Files can be deleted with the remove (or rm) command, and moved or renamed with the move (mv) command:

$ svn rm unwanted-file.txt
D      unwanted-file.txt
$ svn mv badname.txt goodname.txt
A      goodname.txt
D      badname.txt

Remember that nothing really happens in the repository until you commit:

$ svn ci -m "Stuff moved around."
Deleting       unwanted-file.txt
Adding         goodname.txt
Deleting       badname.txt

Committed revision 4.

Occasionally, you should pull changes from the repository. Use the update (or up) command to do this:

$ svn up
At revision 4.

Even though you are the only one working on the project, your working copy isn’t really at the latest revision until you update it from the repository. For example, the “svn log” command shows the history of changes, but only up to your latest “svn update” revision.

That’s all there is to it: now go be productive!

See also

Comments

[gravatar]
I’m surprised you didn’t mention TortoiseSVN (http://tortoisesvn.org/).

TortoiseSVN is a joy to use and it’s all you need to get started with Subversion on Windows. Everything you explain here could be greatly simplified or even skipped.
[gravatar]
There's lots of stuff I didn't mention. In my assumptions I said my work style including liking the command line. I haven't tried TortoiseSVN because I don't tend to use Windows Explorer to move around my files. I'll take a look, though.
[gravatar]
And for integration with Visual Studio...

http://ankhsvn.tigris.org/
[gravatar]
How can you not use Windows Explorer? What are you, retarded? Let me guess you're a unix command line junkie right?
[gravatar]
Thought this might be useful,
This guy provided detailed instructions on setting up Subversion on Windows at,
http://www.clearmud.homeip.net/
[gravatar]
This really is a great starting poing for subversion on Windows. Thanks for the help!

Also, I didn't know if you had noticed this yet, but this web page has been linked to by 50 different people on http://del.icio.us (as of 4/6/2005). Not too shabby for a tutorial on a blog.
[gravatar]
Joseph Desjardins 2:34 PM on 1 Nov 2005
Very helpful. Your instructions got me up and running in minutes.


ps -- craig, some people find the command line efficient. Notice how i didn't call you a name...:-)

[gravatar]
6 months ago I tested svn but I found it not clear enough, so I gave up after some days of use.
Now, by reading this article, I though come on, give it a try.
After nearly one hour I have still not yet even imported my project!

First, I had trouble executing this line:
svnadmin create c:\svn\myproj

It didn't work until I moved to c:\svn

Next problem was the import:
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found

So I used -m option and the next problem was:
svn: Unable to open an ra_local session to URL
svn: Unable to open repository 'file:///c:/svn/myproj'

So I read that I have to verify if ra_local is installed by typing:
svn --version

which results in:

svn, version 1.2.0 (r14790)
compiled May 22 2005, 22:40:26

Copyright (C) 2000-2005 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

So all seams ok but svn refused to import.
Then I remembered that I used TortoiseSVN at the time and I started it. I could get my old repository via file://... protocol.
I don't know why svn doesn't import to my new created repository but one thing is clear: I don't trust into such cranky software and don't want to lose still more time.
[gravatar]
6 months ago I tested svn but I found it not clear enough, so I gave up after some days of use.
Now, by reading this article, I though come on, give it a try.
After nearly one hour I have still not yet even imported my project!

First, I had trouble executing this line:
svnadmin create c:\svn\myproj

It didn't work until I moved to c:\svn

Next problem was the import:
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found

So I used -m option and the next problem was:
svn: Unable to open an ra_local session to URL
svn: Unable to open repository 'file:///c:/svn/myproj'

So I read that I have to verify if ra_local is installed by typing:
svn --version

which results in:

svn, version 1.2.0 (r14790)
compiled May 22 2005, 22:40:26

Copyright (C) 2000-2005 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

So all seams ok but svn refused to import.
Then I remembered that I used TortoiseSVN at the time and I started it. I could get my old repository via file://... protocol.
I don't know why svn doesn't import to my new created repository but one thing is clear: I don't trust into such cranky software and don't want to lose still more time.
[gravatar]
Thanks so much for showing how to do it on the command line!!!
[gravatar]
Really usefull piece of knowledge.
[gravatar]
WIndozeDoesNotExist 5:17 PM on 14 Jun 2006
When i see that people is unable to use a powerfull yet simple tool like svn, i understand perfectly why Windows+SourceSafe is misused all around the world!

Open your mind!
[gravatar]
Nice work. Downloaded subversion, read through a fair few pages of their book and then came here. I had a webpage I created in a project, checked out, diffed and checked in within minutes.

And I think the command line approach is best for learning as it shows you the basics under those layers of graphics.
[gravatar]
I was following instructions, but did not succeed.

When using command 'svn import' always an error is occuring after some files have been added (translation from German): 'svn: File 'd:\svnrepos\askeet\db\transactions\0-1.txn\rev' cannot be opened: The process cannot access the file because it is being used by another process.'

Interestingly folder '0-1.txn' is not being created in repository. And this message is not occuring in a reproducible manner. Sometimes after several tries of importing corresponding folder '0-1.txn' is suddenly emerging!

But I did not achieve a single import. Always after several files have been added, this error is emerging.

Any hints?
[gravatar]
great stuff. thanks ned...

for anyone looking for a windows svn installer get one here

It included TortoiseSVN for GUI svn inteface, but I prefer the command line, and these instructions were great.
[gravatar]
schmiroh

I ran into a similar issue.
The problem was that my virus scanner on the server was not able to complete it's scan of content written to the transaction data before a new write was attempted by the svn server.

I fixed this by disabling my virus scanning on this section.

(Norton Antivirus File System Protection)
[gravatar]
This is very clean and simple and what I was looking for.

BTW: I live on the command line in Windows because its the foundation for many programs, and anyone serious about learning CVS/SVN - since they started at the command line, one needs to learn the command line. Often I ssh in and the command line has saved me much headache from graphical interfaces not doing exactly what I need - PHPMyAdmin is one fine example. If one is not serious about being a true expert in CVS/SVN, then they should download GUI tools that hide whats going on and click away.
[gravatar]
I had much difficulty getting the latest versions of SVN (as of March 2007) and ancillary applications to all behave correctly on a DOS platform but I was eventually able to wrestle the bear to the ground! Wish I had found this post earlier!

One of the first problems I had was getting past all the svn examples which are for *nix systems and when it said to:

svn import mysourcetree file:///svn/repos -m "a comment"

I took the third forward slash in file:/// to be part of the *nix path
to /svn/repos

So I got stuck on trying to DOS-ify the example by

svn import mysourcetree file://f:\svn\repos

Anyway to make a long story short, you
have the correct incantation in step 3!

I finally got svn 1.4.3 repository created and loaded with my first rails
project and maybe now I wanted to manage it from eclipse via subclipse. Oh yeah babe!

Here begins more problems for anyone who cares.

The mod_dav_svn.so apache modules that came with the one-click DOS installer for svn 1.4.3 were incompatible with the latest apache server version 2.2.4 that I had installed. I went back to the subversion
web site and stumbled on this little note at the top of the download page

ATTENTION!: The mod_dav_svn binaries available here are NOT compatible with Apache 2.2
-- see the Windows Apache 2.2.x folder.

In there, I found the file: svn-win32-1.4.3.zip
with description: Subversion 1.4.3 Win32 binaries for Apache 2.2.x.
The filename is the same as a file in the original directory that apparently has different shared-object libs in it!!!

Anyway, the one-click installer that I originally downloaded and used to install svn does magical things like add the all-important environment variable APR_ICONV_PATH (rrriiiigggghhhht!!) and the zip file does nothing of the sort so it isn't good enough to unzip the apache 2.2 verson of svn. I ended up installing svn via the one-click DOS installer so that at least svn worked by itself. THEN I extracted the svn/bin/mod_dav_svn.so file from the apache 2.2 version of svn-win32-1.4.3.zip and put that file into c:\apache\apache2.2\modules then after some minor http.conf tweeks that actually matched the svn documentation, I was able to get apache to serve up the repository created above!!!!!!!
[gravatar]
Certainly we should give a try for SVN. It will be the successor of CVS yet

Bye
Charlles
Brazil & Samba
[gravatar]
This does work to me - but what about multiple users? How do I separate access to my repository?
[gravatar]
I mentioned at the top that this was only useful for a one-developer project. For multiple users, you need to find a server to use.
[gravatar]
Hi,

I have this scenario:
a subversion repository shared between many users with several Netbeans projects inside, and I wish to be able to ignore every warning about differences on directories like nbproject (these contain info on the local settings for each user, thus, being useless keep them on sync).

I tried using nbproject*, *nbproject* and nbproject, but the warnings continues overwhelming me.

What am I doing wrong?
[gravatar]
Very nice. I had everything squared away in about 5 minutes (you might mention -m and -f switches for the import command). Have to confess that I won't be command-lining so much. I'm a Subclipse junkie.
[gravatar]
To solve the following:

Unable to open an ra_local session to URL
Unable to open repository

I did a perfect install of subversion, repos, a development checkout and a staging area export. I installed tortoise svn and all was beautiful.

Then I rebuilt the UNIX server and TortoiseSVN kept showing me the above errors.

Besides spending alot of time on trying to track down an issue on the UNIX server as I had repaired and reloaded TortoiseSVN and was still getting the errors, I noticed that when I had set up samba some drives that I had mapped had changed, TortoiseSVN kept the old pathways to non existent repository path. This is a windows caching issue or tortoise doesn't destroy all the temp files it makes even when deleted and reinstalled or repaired. I hope this helps to stop wasting time on this issue.
[gravatar]
Has anyone figured out how to import a single file into a repository w/ TortoiseSVN? Or a group of files would be better since I have several thousand files that need to be added. I cannot add the top-level folder since it contains many sub-folders (most of which need also to be in SVN but not all, e.g. images, logs).

Maybe if I could figure out how to write one of those ignore.txt files? If I only knew which folder it went in and what the syntax is to avoid a few folders by name. Arghhh!
[gravatar]
for all those had problem with "unable to open an ra_local" "unable to open repository" go to: http://abbeyworkshop.com/howto/misc/svn01/ and follow steps....
[gravatar]
regarding the SVN_EDITOR on windows, if you got persistent error ( returned 32512 err) try changed the directory separator:

set SVN_EDITOR=c:/windows/notepad.exe
[gravatar]
For thos who have the problem with the svn: Unable to open an ra_local session to URL my solution was : svn import [name_of_the_dir_only_without_the_"c:/"] Example,
Assuming everything is on the c: for windowsers ->
svn import pj file:///c:/svn_repository -m "init"
[gravatar]
Take car about slashes everithing has to be "/" and not "\" after file:///
[gravatar]
Here are instructions for setting up an svn server on Windows that can be accessed from other boxes: http://grok-code.com/115/how-to-setup-a-windows-svn-repository/
[gravatar]
Ned, Thank you for creating the documentation. I'm sorry that Craig was so rude. Ever since his Mom refused to go to prom with him, he's been a little edgy.
[gravatar]
brilliant, re-life problems covered indepth
[gravatar]
Excellent Stuff Ned, Thanks very much.
[gravatar]
Ned, very interessting article!

Just read a tweet from Scott Hanselman about a new product SVNIsapi (http://www.svnisapi.com) which provides Subversion support via IIS. No need to setup an Apache or SVNSERVE any more.
[gravatar]
Very nice tutorial. This is exactly what I was looking for in setting up subversion to keep track of my personal projects.
[gravatar]
Cool tut man! Wish I had seen this before struggling with svn import with giving file url as "file://blah/blah"... Thanks for mentioning the right way to do it.. If you can write about how to use svn server "svn://blah/blah" in local machine, it'll be awesome... :)
[gravatar]
A wunderful tutorial ... it not only got me up and running but also helps me every now and then to resolve my queries lest i forget them.

Thanks mate ... its good to have ppl like u
[gravatar]
Very clear and concise tutorial. I was looking at importing via a URL and was having no luck. Tried this way and it worked the first time!!!
[gravatar]
I've just written some instructions for setting up a Windows system for SSH access to a repository: www.murdoch-sutherland.com/svnuser.html. My instructions don't say what to do once you have it set up; I think yours are great for that.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.