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

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.