As I have previously mentioned, I am a big fan of managing code changes with Subversion. Here I’m going to describe the process of creating your own local repository for managing changes. Think of Subversion as you own personal time machine for your content.
My basic setup will be to have the repository (where subversion stores all of your changes) on a secondary partition on my laptop’s hard drive. While I had considered having it remotely on my server, I want to have it local so I can manage my content when I am off-line traveling. I will also use backup routines to have copies on external drives. While I prefer to work in Linux, I also work in windows, so I will describe the setup from a windows point-of-view. However, the files for the repository are on a shared partition of my hard drive so I can access the repository not matter which OS I’m using at the moment.
The basics steps are these:
- Install Subversion & optionally, TortoiseSVN for windows
- Create directory to store repository
- Create repository with svnadmin
- Import web project
- Checkout working copy of web project
Install Subversion & optionally, TortoiseSVN for windows
Subversion & TortoiseSVN are available from the Open Source projects at Tigris.org:
Follow the link to the individual download pages and download the current version for your OS. Install in the usual manner! Note, TorotoiseSVN requires a reboot since it integrates with windows explorer.
Create directory to store repository
Hopefully, if you know dos, this will be familiar. Or maybe it won’t if you have never used the command line under WinXP. Since subversion itself is a command line program, creating the repository will be at the command line. so let’s start by using the command line to create the needed new directory. Click Start -> Run… (or Windows-R from keyboard) and type
cmdand press Enter. A new window with white text on a black background will open with a prompt showing your current directory. Decide where on your drive, or drives, you would like to locate the repository. Then create the directory with
C:> md e:svn-repo
Substitute your own drive letter instead of e: and path of your choice instead of svn-repo.
Create repository with svnadmin
Now that you have a directory to use, we use
svnadmin to turn it into a repository for use by subversion.
C:>svnadmin create e:svn-repo
Let’s see what it created for you:
Directory of e:svn-repo 04/01/2007 05:53 PM <DIR> . 04/01/2007 05:53 PM <DIR> .. 04/01/2007 06:20 PM <DIR> dav 04/01/2007 06:20 PM <DIR> locks 04/01/2007 06:20 PM <DIR> hooks 04/01/2007 06:20 PM <DIR> conf 04/01/2007 06:20 PM 234 README.txt 04/01/2007 06:20 PM <DIR> db 04/01/2007 06:20 PM 2 format
Don’t worry anything about the details now, but I just wanted to show you that subversion is doing a lot of work for you behind the scenes.
Import web project
Next step is to import that web site you have been working so hard on! Since we have been working at the command line, I will continue here with that technique. Then I will show you the easy way with TortoiseSVN–a graphical tool to access the power of subversion from windows explorer.
First, locate the directory where you current web site files exist on your drive. If you have multiple sites, I will suggest that you import them as separate ‘projects’ in subversion.
cd to the top-level directory you want to import–all subdirectories will be imported also. You should clean them up before importing, removing any test or temporary files you do not want in the repository.
C:>cd htmlcdchase-blog C:htmlcdChase-blog>
Next, you will use
svn import to pull in all of the content to the repository. Last chance to clean up the directory and sub-folders before importing! Notice the use of -m “Importing blog.cdchase.com project” to supply a log comment. All changes to a subversion repository require a comment describing the change.
C:htmlcdChase-blog>svn import -m "Importing blog.cdchase.com project" . file:///e:/svn-repo/cdchase-blog/trunk
You will see all of your files scroll by as they are imported. Eventually, you will get to the last line:
Committed revision 1.
Congratulations! You now have your first project in the subversion repository!
Before we move on, let me point out two items in the import command above. First, the ‘.’ (dot or period): it is how you refer to the current directory as a shortcut. If you were not already in the directory you wanted to import, you could explicitly provide it instead of using the dot. Secondly, the format of the destination: file:///e:/svn-repo/cdchase-blog/trunk. This is the URL format for referencing a local file location. The file:/// replaces the use of http://hostname/ as in a web browser. The remainder is the path to the repository, including the desired project name, cdchase-blog, in my case; and the branch you want to import it to, trunk. More on the use of ‘trunk’ in a future post. The ” at the end of the first line is just to indicated that this line is continued on the next line–don’t type this in windows! The entire command should be one line, without the ”. (Linux users may recognize this as the standard continuation character.)
Importing with TortoiseSVN
As promised, doing the same import function with TortoiseSVN is as simple as right-clicking on the folder you wish to import, and selecting TortoiseSVN -> Import…
(image no longer available)
and supplying the destination path and log message:
(image no longer available)
Once you click ‘OK’ your files will be submitted as in the command line version.
Checkout working copy of web project
Finally, in order to actually use the files from the repository, you must ‘check out’ the files. This must be done to a new directory, so if you want to use the same directory name you imported from, rename that directory first.
C:html>rename cdchase-blog cdchase-blog-old
To do the ‘checkout’ or co:
C:html>svn co file:///e:/svn-repo/cdchase-blog/trunk cdchase-blog
When it is complete, you will see:
Checked out revision 1.
Congratulations! Your files are now under version control!
Tomorrow, we will go deeper into how you use Subversion on a daily use basis.