Importing an existing project to Subversion
I am a cvs user, but recently decided to check out subversion, which I'm using for some personal projects. The biggest challenge I ran into was just figuring out how to get my project set up the way I wanted. The documentation I could find was either too general, or took an approach I didn't like. So here's my quick guide to setting up a new subversion project for an existing codebase. This guide assumes the following:
1) You already have created your repository
2) For the purpose of the examples, I access my repository using webdav, and my repository is at http://localhost:8080/svn
The biggest difference between subversion and cvs in my eyes is how branches and tags are stored. In subversion, branched or tagged code exists in a separate directory hierarchy from the trunk. So a project's base directory generally has three directories under it: trunk, branches, and tags. The code goes in the trunk directory, and gets copied into the other directories when you branch or tag it.
For the purposes of this example, here's what my project layout looks like:
/home/project
/home/project/config
/home/project/docs
/home/project/source
I want "project" to be the name of my project, so I will browse to it at http://localhost:8080/svn/project. But I don't want the trunk, branches, or tags directories in my checkout location, as they just exist for subversion's benefit. Why subversion doesn't just create them for you and make their existence invisible, I don't know. I wish it did. But it doesn't, and you need to manually create them. The easiest way to do that is to create an import template in a temporary directory:
mkdir /tmp/import
mkdir /tmp/import/project
mkdir /tmp/import/project/trunk
mkdir /tmp/import/project/branches
mkdir /tmp/import/project/tags
Now, go into your temporary directory and import the template to create the project in subversion:
cd /tmp/import
svn import . http://localhost:8080/svn -m "initial checkin"
Now that my project template has been imported, I can go to my actual project directory and do a checkout there to get it under revision control:
cd /home/project
svn co http://localhost:8080/svn/project/trunk .
Now whatever I add from my project directory will get added under project/trunk in the subversion repository. I can start adding my directories:
svn add config/ docs/ source/
svn commit -m "added"
Now my project is created, and I can browse to my source files in the repository at http://localhost:8080/svn/project/trunk/source.
1) You already have created your repository
2) For the purpose of the examples, I access my repository using webdav, and my repository is at http://localhost:8080/svn
The biggest difference between subversion and cvs in my eyes is how branches and tags are stored. In subversion, branched or tagged code exists in a separate directory hierarchy from the trunk. So a project's base directory generally has three directories under it: trunk, branches, and tags. The code goes in the trunk directory, and gets copied into the other directories when you branch or tag it.
For the purposes of this example, here's what my project layout looks like:
/home/project
/home/project/config
/home/project/docs
/home/project/source
I want "project" to be the name of my project, so I will browse to it at http://localhost:8080/svn/project. But I don't want the trunk, branches, or tags directories in my checkout location, as they just exist for subversion's benefit. Why subversion doesn't just create them for you and make their existence invisible, I don't know. I wish it did. But it doesn't, and you need to manually create them. The easiest way to do that is to create an import template in a temporary directory:
mkdir /tmp/import
mkdir /tmp/import/project
mkdir /tmp/import/project/trunk
mkdir /tmp/import/project/branches
mkdir /tmp/import/project/tags
Now, go into your temporary directory and import the template to create the project in subversion:
cd /tmp/import
svn import . http://localhost:8080/svn -m "initial checkin"
Now that my project template has been imported, I can go to my actual project directory and do a checkout there to get it under revision control:
cd /home/project
svn co http://localhost:8080/svn/project/trunk .
Now whatever I add from my project directory will get added under project/trunk in the subversion repository. I can start adding my directories:
svn add config/ docs/ source/
svn commit -m "added"
Now my project is created, and I can browse to my source files in the repository at http://localhost:8080/svn/project/trunk/source.
Labels: code, subversion