asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Introduction to Version Control with Subversion
By John Peterson
Rating: 3.5 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article



    Introduction

    Whether you call it source control, version control, or source code management, if you're in the business of software development, providing a safe repository for your code is critical.

    Most of us know that we should be using some sort of source control software. Developers who work on team projects usually don't have a choice... after all, someone needs to act as a traffic cop to keep order. But source control has benefits to offer the lone developer as well. While products like Microsoft's Visual Source Safe and Visual Studio Team Foundation Server are often out of the price range for most individual developers, that doesn't mean you should forego source control altogether.

    This article will offer a quick introduction to Subversion, an open-source version control system that you can get for free and have up and running in just a few minutes.

    Installation

    You can find links to download the Subversion from the Subversion Project's Getting Subversion page. Actually the most likely problem you'll have is that you'll find too many links and not know which one to use. Tending to want to get things straight from the source, I'd recommend you download the release directly from Tigris.org. You'll find the link in the Windows binaries section.

    For those of you having trouble finding it, the link I used is subversion > Releases > Windows. Once there, you'll see a number of files. I'd recommend you choose the highest version number available as a Windows MSI installer. As I write this that is Setup-Subversion-1.5.3.msi.

    Initial setup is a breeze:

    Subversion

    Subversion

    You can simply use the defaults for most of the options. The one screen that might confuse you some is the one labeled "Select Apache Binding". Subversion can be configured to use Apache as its server. For the purposes of this article, we'll be using Subversion's built-in server: Svnserve. Unless you plan on using Apache with Subversion, this setting doesn't matter. If you are planning on using Apache, choose the setting that corresponds to the version of Apache you have installed.

    Subversion

    Subversion

    Subversion

    Creating a Repository

    A repository is where subversion stores all your files. It's basically a database designed to store files and information about them. Before we can do much of anything we need to create a repository. I'm going to place it on the root of my computer's C: drive and call it "svn_data".

    1. Open a command prompt window.

    2. Type the following command:

      svnadmin create C:\svn_data

    If you decide to keep your repository in a different location simply replace "C:\svn_data" with the full path to the location where you want Subversion to create your repository.

    Setting Up a Server

    If you work alone and you'll only be accessing your Subversion repository from the local machine it is possible to start using it immediately after installation using the file:// protocol. Personally I prefer using the server-based method and recommend that you take the few seconds it takes to set up a server even if you do fit the criteria above.

    As I mentioned earlier, I'll be using Svnserve. According to the documentation:

    Svnserve - a lightweight stand-alone server which uses a custom protocol over an ordinary TCP/IP connection.

    In most cases svnserve is easier to setup and runs faster than the Apache based server. And now that SASL support is included it is easy to secure as well.

    To install Svnserve as a Windows service and set its root to the repository we just created, enter the following command at a command prompt. If it's still open, you can use the same command window you used to create your repository.

    sc create svnserve binpath= "\"C:\Program Files\Subversion\bin\svnserve.exe\" --service --root C:\svn_data" displayname= "Subversion Server" depend= tcpip start= auto

    It's a long command so it probably line wrapped in your browser, but that should all be on one line. If you installed Subversion to a different folder or chose a different location for your repository, you'll need to modify the command to reflect those differences.

    Once installed you'll need to start the service which can be done by simply rebooting or typing the following command line:

    net start svnserve

    Once you've installed your Svnserve-based server, you'll access it via the svn:// protocol.

    Seting Up User Accounts

    Next you'll need to setup usernames and passwords to track the users that are able to access your repository. You can do this by editing the "C:\svn_data\conf\svnserve.conf" and "C:\svn_data\conf\passwd" files.

    In "C:\svn_data\conf\svnserve.conf", just uncomment the line that says "password-db = passwd". That tells it to look to the "passwd" file to get a list of usernames and passwords. Obviously the next step is to edit "C:\svn_data\conf\passwd" and add a line with your desired username and password. It's pretty simple and the files are commented quite well.

    Importing a Project Into the Repository

    What you store in your repository and how you store it is totally up to you. For illustration, I'm going to work with a very simple folder called "C:\MyWebSite" that only contains two files "default.htm" and "products.htm".

    I'm going to ignore the whole trunk, branches, tags structure for the time being. I do recommend that you do a search and read up on the concept before you decide on a structure for your own repository. A good place to start is Chapter 4. Branching and Merging from O'Reilly Media's "Version Control with Subversion".

    To get your project into Subversion's repository, you use the "svn import" command. Here's the sample command you should use if you've been following along with the example:

    svn import C:\MyWebSite svn://localhost/MyWebSite -m "Import MyWebSite"

    Notice that we were able to omit the path to the repository since we specified the root folder when we installed the svnserve service.

    You'll be prompted for your username and password. Once you enter them you should get a result similar to the following:

    C:\>svn import C:\MyWebSite svn://localhost/MyWebSite -m "Import MyWebSite"
    Authentication realm: <svn://localhost:3690>
    Password for 'username': ********
    Adding         C:\MyWebSite\products.htm
    Adding         C:\MyWebSite\default.htm
    
    Committed revision 1.
    

    Granted our sample project is quite small, but its now stored in our Subversion repository and has been given a revision number.

    Checking Out a Project

    Now that our sample project lives in the Subversion repository, if we need to make any changes we first how do we get a working copy. This is done via the "checkout" or "co" command. I'm going to checkout the whole folder.

    1. Open a command prompt window.

    2. Change to the folder in which I want to create my working copy.

      CD \Temp

    3. Type the following command:

      svn checkout svn://localhost/MyWebSite

    4. You should see a result similar to the following:

      C:\Temp>svn checkout svn://localhost/MyWebSite
      A    MyWebSite\products.htm
      A    MyWebSite\default.htm
      Checked out revision 1.
      		

      And you should have a new folder named "C:\Temp\MyWebSite" that contains the two files.

    Committing Changes

    Now that I've checked out my sample project. It's time to make some changes. I'm going to add some additional HTML to my working copy of the "products.htm" file.

    Once the changes are made, it's time to check and see what those changes were and add them back to the repository.

    1. If you aren't still there, open a command prompt window and change to your working folder.

      CD \Temp\MyWebSite

    2. To see the differences between your working version of a file and the version in the repository, use the "diff" or "di" command:

      svn diff products.htm

      Notice we don't need to specify the full path (since we're in the working folder) or the repository (since Subversion manages this information on checked out files for us).

      You should see something like the following depending on the changes you made to the file in question:

      C:\Temp\MyWebSite>svn diff products.htm
      Index: products.htm
      ===================================================================
      --- products.htm        (revision 1)
      +++ products.htm        (working copy)
      @@ -6,5 +6,11 @@
      
       <h1>Products</h1>
      
      +<ul>
      +<li>Product 1</li>
      +<li>Product 2</li>
      +</ul>
      +
      +
       </body>
       </html>
      		
    3. Now that we've seen the changes and we're sure we want to commit them, we use the "commit" or "ci" command.

      svn commit products.htm -m "Added Product1 and Product2"

      Unlike most of the other commands, this one requires that you include a comment. This should briefly but accurately describe the changes that you're checking in.

      C:\Temp\MyWebSite>svn commit products.htm -m "Added Product1 and Product2"
      Sending        products.htm
      Transmitting file data .
      Committed revision 2.
      

    Updating the Working Copy

    Now that we've checked in our changes, you might think that our local copy is back in sync with the server, but that's not the case. If you take a look at the output from the "svn info" command, you'll notice that it still says we're using revision 1. In order to get our working copy up to date we need to use the "svn update" command. Running update will get the latest versions from the server and if it succeeds will display a status message that looks like this:

    At revision 2.

    or whatever version your repository happens to be up to.

    Conclusion

    I hope this article has shown you just how simple version control can be. I showed you how in just a few minutes you can set up and start using your very own Subversion repository and server. In this article we focused on the server-side of things and some very basic command-line based client-side operations. Next time we'll examine some of the graphical tools that help make using Subversion even easier and can even integrate it into Visual Studio.

    In the mean time, you might find the following links useful:

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 21, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 1
    While the .NET Framework made building ASP.NET applications easier then it had ever been in the past, .NET 2.0 builds on that foundation in order to take things to the next level. This article shows you to how to construct an N-Tier ASP.NET 2.0 Web application by leveraging the new features of ASP.NET 2.0 and SQL Server 2005.
    [Read This Article]  [Top]
    Apr 28, 2005 - New Files and Folders in ASP.NET 2.0
    With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. As part of this release, ASP.NET 2.0 also comes with a host of new special files and folders that are meant to be used to implement a specific functionality. This article examines these new files and folders in detail and provides examples that demonstrate how to utilize them to create ASP.NET 2.0 applications.
    [Read This Article]  [Top]
    Mar 10, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2, Cont'd
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 9, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 3, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1, Cont'd
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Mar 2, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Feb 16, 2005 - Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
    In ASP.NET 2.0 and Visual Studio 2005, you can quickly program custom authentication pages with the provided Membership Login controls. In this article, Dina Fleet Berry examines the steps involved in using the Login control with a custom SQL Server membership database.
    [Read This Article]  [Top]
    Dec 29, 2004 - ClickOnce Deployment in .NET Framework 2.0
    In this article, Thiru Thangarathinam examines .NET 2.0's new ClickOnce deployment technology that is designed to ease deployment of Windows forms applications. This new technology not only provides an easy application installation mechanism, it also eases deployment of upgrades to existing applications.
    [Read This Article]  [Top]
    Dec 15, 2004 - A Sneak Peek at ASP.NET 2.0's Administrative Tools
    With ASP.NET 2.0, Microsoft has made great strides in increasing developer productivity and has made implementing previously complex solutions relatively easy. Where this version of ASP.NET really shines, however, is in its new administrative tools that allow developers to spend less time managing the configuration of the servers and software and more time developing great code.
    [Read This Article]  [Top]
    Nov 17, 2004 - The ASP.NET 2.0 TreeView Control
    Thiru Thangarathinam introduces ASP.NET 2.0's new TreeView control which provides a seamless way to consume and display information from hierarchical data sources. The article discusses this new control in depth and explains how to use this feature rich control in your ASP.NET applications.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers