Bernhard Häussner

Howto: Start using Subversion

31.01.2010, 14:46


Sometimes you want to start using Subversion code control with an existing project. This tutorial explains the steps required to create a repository and add the files of the existing project.

Start by creating a repository:

svnadmin create /dir/to/store/repo/repository-name

This will create a directory „repository-name“ containing the database of files and revisions.

Then let's add some internal directories to our repository:

svn mkdir file:///dir/to/store/repo/repository-name/trunk \
 -m "Creating repo directory structure"

Now that you have created the repo-directory that should contain all the files, import the existing project files. Start by checking out the empty repo-dir to into your project dir. This will make your project dir a working copy (that is: create a dir named „.svn“ containig some internal info) but won't change anything else.

cd /existing/poject/dir
svn checkout file:///dir/to/store/repo/repository-name/trunk .

Then go on adding (or planing to add) all the files:

svn add *

This command will list all the files that will be loaded into the repository. You can always look at the planned changes with svn st.

You probably want to exclude some files such as configuration files, runtime data. You just have to revert the add-command again:

svn revert runtimedata # exclude whole dir
svn revert config/my.ini # exclude single file

Then apply the changes to your repository (commit it):

svn commit \
-m "initial import"

And that's it. You project is added to the repository without extra files. That can be crucial if your runtime data has a huge file size. If you're paranoid or just curious check the repository for success:

svnlook tree /dir/to/store/repo/repository-name

This should show the imported directory tree. Now you can start making changes to your files and commit them as usual.

vim app.cpp
svn commit -m "typo"
svn log -r 1:HEAD #show full revision history

If you ever got stuck, you may use the built in help:

svn help #list commands
svn help commit #list options
svnlook help tree #works too

I will start using subversion for everything... soon.

Kurze URL Post to twitter


Julian Schrader meint: (#218)
01.02.2010, 12:56

Did you evaluate other version control systems before you wanted to use svn for everything?

In case you're not yet fully set, let me propose using git: A git'ed project always has its repository with it, so working over multiple machines is less of a hassle—and it allows for far better merging than other SCMs.

Bernhard H. meint: (#219)
01.02.2010, 21:45

I didn't really test VCSs excessively (well, i would probably have written about that instead...) but I read about Mercurial and Git too. Both don't have as much community and (in case of Git) documentation available as SVN. And I'm using Trac, which uses SVN natively.

Any direct comparisons between SVN and Git pointed out that Git is distributed. With SVN you don't have a copy of the repo on your machine, but you just commit to the central repository (or a branch). That should work across multiple machines nicely. You don't have to manage your very own repo. Working offline may be a bit painful, you could still merge your code afterwards. But I'm not really working offline. So "distributed" just adds complexity, doesn't it?

If you'd want to go distributed, Git is not as CVS-compatible as hg (and svn of course), but has on the other hand less features than hg, which is distributed too (cf. So I'd rather use hg.

Of course SVN for "everything" is a bit to much, looking at existing projects like go with hg, and the code on Github.

If I'd ever change my mind there's still git-svn so let's see how SVN is doing.

Me meint: (#227)
04.06.2010, 13:50

It's not fair to say git has less features than hg, and that's comming from a hg user.

And yes, DVCS are probably better then non-distributed VCS after all.

Bernhard H. meint: (#228)
05.06.2010, 16:29

This is just a simple provocative statement though, could you prove that or give examples? Do you have any reliable sources? I'm always interested.

© 2008-2018 by Bernhard Häussner - Impressum - Login
Kurz-Link zu dieser Seite: