Setting Up Subversion for Development on Windows
By Akash Mehta2008-07-02
Working with Subversion
To manage our code using our SVN server, we're going to need a client. One of the most popular clients for Windows, which we'll be using today, is TortoiseSVN. Tortoise integrates well with the Windows shell: we'll generally be using it through the right-click context menu in Windows Explorer. Tortoise is fairly transparent, integrating cleanly while providing helpful information all over your project. It also works out of the box with IDEs that provide access to the shell menu, such as PhpED.
Download the latest copy of TortoiseSVN from the project page - I'm using v1.5.0. Install it with all the default options.
Importing our project into the repository
We'll use TortoiseSVN to place a particular folder under version control.
Let's create a sample project with a PHP script in it. I'm storing my project in
C:\projects\helloworld with an index.php file inside,
although it doesn't matter where you store your project or what files are inside
it.
Load up a Windows Explorer window and navigate to the folder above your
project folder - for example, C:\projects. Right-click on your
project folder - e.g. helloworld - and select TortoiseSVN >
Import.

Importing the folder will place its contents into our SVN repository - we just need to tell it which SVN repository. Head back to your VisualSVN Server Manager, select 'Repositories' from the tree on the left and click on our new test repository. This will allow you to view the contents of your repository - currently, it only holds the three default folders. We're after the URL to the repository, which will depend on your computer name / hostname and the port you chose during installation. In a gray bar above the repository browser, VisualSVN will state the name of the repository and its URL. To save an extra step, right click on the repository in the tree and select "Copy URL to clipboard":

Then head back to your import dialog, add "trunk" to the end of the URL and hit "OK":

Remember to enter the username and password we set earlier. You'll see a confirmation dialog, including a note that we're currently at revision #2. Next, we checkout from the repository to that same folder, so that we have a copy that is offically under version control. You can do this with the right click menu again - right click on "helloworld", and click "SVN Checkout". The default settings in this dialog are all fine, except the "Checkout directory" - you may need to remove a "test" from the end. This is automatically added when your folder name is not the same as your repository name. Your Checkout dialog should be similar to this:

Hit "OK", allow TortoiseSVN to overwrite the contents of the directory, and we're ready to go. The folder will now have a green tick icon on its thumbnail, showing that it is under version control and is at the latest version.
Handling updates
Let's make some changes to our project files. We're going to add a line to
the source file in our project folder, as well as create an empty file called
empty.txt in the same folder. When we want to save the current
state of our code in the SVN repository, we commit the changes to the
repository. When we've made these changes, the icon overlays on the file
thumbnails will show us that our files are not at the latest version:

The question mark icon on "empty.txt" shows that the file is not versioned - as it's new - and so SVN doesn't know what to do with it. The red icon on index.php indicates changes have been made and the file is not the same as the latest in the version control. Right click anywhere in the folder and select "SVN Commit". We can now enter a human-readable summary message identifying what changes have been made, and select any new files that need to be versioned. Make sure you check the box next to your new file so that it is entered into the repository:

Thanks to the information in the .svn directory, Tortoise knows
exactly what repository we are committing to. Hit "OK" to make the commit:

And we're done!
Tutorial Pages:
» Introducing Subversion
» Setting up a Subversion server on Windows
» Working with Subversion
» Further reading
