Pages

Tuesday, August 28, 2012

Short novice guide for importing a project to Subversion

My new employer uses Subversion as the central version control system, so I'm trying to take the first steps as my former employer still used the good old CVS. (This also means that you don't find advanced infos here but only novice infos.)
(And of course, it would be nice, if my new employer would use Git, however, Subversion and Git can co-exist as you may know already. But this is not the subject of this blog entry.)
So, how to import an existing project to Subversion? I don't mind loosing the history of the project, of course this makes the whole migration process a lot easier.

1. Create a Subversion repository

First, a central Subversion repository has to be created if it does not exist already:
$ svnadmin create /svn/repos

2. Import an existing project to the trunk

So, let's import the project directory myproject to Subversion. I already learned that the recommended structure should be as follows:
myproject/
  trunk/
  tags/
  branches/
As in a non-Subversion project, the trunk, tags and branches directories usually do not exist yet, they have to be created first. The import sequence for the project directory myproject becomes as follows:
$ cd <parent directory of the project directory myproject>
$ mkdir myproject_svn myproject_svn/tags myproject_svn/branches
$ mv myproject myproject_svn/trunk
$ svn import myproject_svn file:///svn/repos/myproject
As the Subversion repository is locally visible, I use the file:// schema.
Don't forget the myproject in the last command or all files in svn_myproject will be imported directly into the root directory of the repository.
You cannot work directly with the created myproject_svn directory above, you first have to checkout it again:
svn checkout file:///svn/repos/myproject/trunk -d myproject

3. Create a branch

Creating a branch is just a Subversion copy:
$ cd myproject
$ svn copy trunk/ branches/myproject-branch
$ svn status
A +  branches/myproject-branch
Here, the trunk/ directory is copied recursively in the working directory brances/myproject-branch. The output of the command svn status indicates that the directory is ready to be added to the repository. The + says that branches/myproject-branch is just a copy and nothing new.
When commiting, Subversion creates the directory in the repository:
$ svn commit -m"creating new branch"
Adding         branches/myproject-branch
Committed revision 987.
Subversion does not really copy all files, but just creates a new repository entry pointing to the original tree, so this is also called a "cheap copy". Please refer to the Subversion documentation for more detailed infos.
The one step method without the need of a temporary directory is as follows:
$ svn copy file:///svn/repos/myproject-trunk \
  file:///svn/repos/myproject/branches/myproject-branch \
  -m"creating new branch"

No comments:

Post a Comment