Getting Started with a Repository and Working Copy
Let’s get started by creating a repository and a working copy, as described in my previous article, "Getting Started with Subversion on Windows."
I assume that you’ve downloaded and installed Subversion. With Subversion, it’s allowed to have the repository and working copy on the same machine—a given machine can be a client of its own repository. For a multiuser setup, the repository is typically placed on a server and then shared by other users on the network.
In the sections that follow, I illustrate Subversion commands as they occur inside a DOS console on a given Windows XP host. So although you don’t have to run the commands yourself, you can do so if you prefer. In the interests of brevity, I removed part of the command responses, so your responses will be slightly larger than the ones listed below if you run the commands yourself.
Listing 1 illustrates the commands to create a repository called repo in a folder called repository.
Listing 1 Create a repository
C:\>mkdir repository C:\>cd repository C:\repository>svnadmin create repo
The last command in Listing 1 runs silently (that is, no prompts appear in response to the command). This silent mode is fairly typical for Unix software—Windows software is traditionally much noisier. When you look in the repository folder, you should see something like that illustrated in Listing 2: a subfolder called repo.
Listing 2 A freshly minted repository
C:\repository>dir 07/20/2007 03:58 PM <DIR> repo
So, we now have a repository into which our files can be stored. At this point, there are two choices:
- You can use your existing source code tree.
- You can create completely new files.
I’ll follow the second option in the interests of simplicity. The point is that using your own source code files should not then be too difficult. So, without further ado, let’s quickly create a few files and then drop them into the repository.
The first step is to create a folder and then add some files to it. The folder I create is called C:\repowork\myproject, and this folder in turn contains three subfolders: branches, tags, and trunk. The latter rather strange structure is an optional requirement for more advanced use of Subversion.
In my own use of Subversion, I use this structure, but so far I’ve used only the trunk folder. I use the latter to store all of my source code files. Anyway, as you can see I create two files in Listing 3 and then add them to the trunk subfolder:
Listing 3 Adding some files for version control
C:\repowork\myproject>dir trunk Directory of C:\repowork\myproject\trunk 07/20/2007 04:03 PM <DIR> . 07/20/2007 04:03 PM <DIR> .. 07/20/2007 03:53 PM 11 aFile.txt 07/20/2007 03:53 PM 11 anotherFile.txt
You can add as many files as you like in Listing 3. As pointed out above, you can even add your entire source code tree including subfolders. With a little practice, you’ll be able to create arbitrarily complex repositories. So, to help you become confident, let’s keep it small for the moment.
The last step is importing the files shown in Listing 3 into the Subversion repository. This step is illustrated in Listing 4 using an option of the svn command:
Listing 4 Committing some files to the repository
C:\repowork\myproject\trunk>svn import -m "Initial import" . file:///c:/repository/repo Adding aFile.txt Adding anotherFile.txt Committed revision 1.
As you can see from the key message at the end of Listing 4: Committed revision 1, all the entities in the trunk subfolder have now been successfully imported into the repository. These two files are now said to be under version control. You’re not limited to text files with Subversion—a repository can happily store binary files.
However, we have one more configuration step to do: creating the working copy. To do this, you just create a folder that you will use as your working copy of the source code. I create a folder called C:\repworkarea; I then change to that folder and execute the svn command illustrated in Listing 5.
Listing 5 Creation of a working area
C:\repworkarea>svn checkout file:///c:/repository/repo A repo\aFile.txt A repo\anotherFile.txt Checked out revision 1.
Conceptually, the files in this folder represent your view of the repository. You can change these files to your heart’s content and until you commit those changes nobody else will be affected.
So, you will now work in this folder (C:\repworkarea) when you want to make any changes to the files in your working copy. You might notice that the command in Listing 5 has created a new folder called repo in the folder C:\repworkarea. This just follows the format of the main repository.
So, we now have our repository and our working copy. What about other file types?