<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sandbox Web Solutions &#187; Subversion</title>
	<atom:link href="http://sandbox-ws.com/category/subversion/feed" rel="self" type="application/rss+xml" />
	<link>http://sandbox-ws.com</link>
	<description>Personal Blog of Ahmed El.Hussaini</description>
	<lastBuildDate>Mon, 23 Aug 2010 11:33:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Introduction to Subversion</title>
		<link>http://sandbox-ws.com/subversion/introduction-to-subversion</link>
		<comments>http://sandbox-ws.com/subversion/introduction-to-subversion#comments</comments>
		<pubDate>Fri, 23 Jan 2009 18:41:30 +0000</pubDate>
		<dc:creator>Ahmed El.Hussaini</dc:creator>
				<category><![CDATA[Subversion]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://sandbox-ws.com/?p=320</guid>
		<description><![CDATA[Before I started using subversion I used to make backup of my projects on regular basis and I can&#8217;t emphasis enough how this process was so boring and tedious, and every know and then I forget to make a backup or maybe replace files by accident. Actually I don&#8217;t know how I survived without using [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsandbox-ws.com%2Fsubversion%2Fintroduction-to-subversion"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsandbox-ws.com%2Fsubversion%2Fintroduction-to-subversion&amp;source=sandboxws&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Before I started using subversion I used to make backup of my projects on regular basis and I can&#8217;t emphasis enough how this process was so boring and tedious, and every know and then I forget to make a backup or maybe replace files by accident. Actually I don&#8217;t know how I survived without using some kind of <a href="http://en.wikipedia.org/wiki/Revision_control">version control</a>.</p>
<p><span id="more-320"></span></p>
<p>I&#8217;m assuming that because you&#8217;re reading this article then you probably have some general info about Subversion and maybe some other version control system like <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System">CVS</a>. If not, then no problem, this article will still help you to get started using Subversion.</p>
<p>This article assumes that you&#8217;re running windows xp/vista, but the concept is the same and should work just fine on linux and mac os x systems as well, the only difference will be in the installation which you&#8217;ll find a lot of guides on the internet.</p>
<p>So lets get started, here is an overview of the guide:</p>
<ol>
<li><a href="#Downloading">Downloading and Installing Subversion for Windows</a></li>
<li><a href="#CreatingRepo">Creating a Repository</a></li>
<li><a href="#Initializing ">Initializing Repository Structure</a></li>
<li><a href="#CreatingProject">Creating A New Project</a></li>
<li><a href="#CheckingOut">Checking Out a Project</a></li>
<li><a href="#Adding">Adding Files to the Working Copy</a></li>
<li><a href="#Committing">Committing Changes</a></li>
</ol>
<h5 id="Downloading">Downloading Subversion for Windows</h5>
<p>Subversion for windows can be downloaded from <a href="http://subversion.tigris.org/files/documents/15/43360/Setup-Subversion-1.5.1.en-us.msi">here</a>. After downloading is finished, install the package. If it asks to restart, please do so. In order to verify that the installation was successful open the <strong>command line prompt</strong> and type <strong>svn</strong> then hit <strong>enter</strong> on the keyboard. If you get an output similar to the following then the installation was successful.</p>
<pre class="brush: plain;">
Type 'svn help' for usage.
</pre>
<h5 id="CreatingRepo">Creating a Repository</h5>
<p>Now that we have subversion installed we want to create out first repository. Normally you&#8217;ll want to store the repository on the root of a drive, for example <strong>c:\repo</strong>, so lets use this path to store our repository.</p>
<p>To create a new repository we use the following command:</p>
<pre class="brush: plain;">
cd c:\
svnadmin create repo
</pre>
<h5 id="Initializing">Initializing Repository Structure</h5>
<p>Defining the structure of your repository is completely up to you, there&#8217;s no restrictions in subversion that forces you to structure your repository in a certain way but most developers around the world uses the same structure as a global convention. This structure states that the repository will be divided into three main folders: <strong>Tags</strong>, <strong>Branches</strong>, and <strong>Trunk</strong>. I&#8217;ll not dive into why this structure was agreed upon between developers around the world. I&#8217;ll leave that for another article. Maybe that reason will make you visit my blog again <img src='http://sandbox-ws.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>So lets create the repository initial structure.</p>
<pre class="brush: plain;">
svn mkdir file:///c:/repo/tags file:///c:/repo/trunk file:///c:/repo/branches -m &quot;initialized repo structure&quot;
</pre>
<p>The above command should result in the following output</p>
<pre class="brush: plain;">
Committed out revision 1.
</pre>
<p>Lets explain what happened now, first we used the svn command <strong>mkdir</strong> to create three folders and we also added a message using the parameter <strong>-m</strong>.</p>
<div class="note">
<p>Most svn commands require adding a message while running the command. Those messages are helpful for viewing the history of your repository.</p>
</div>
<p>After running the <strong>mkdir</strong> command <strong>svn</strong> reports that the repository revision number is now <strong>(1)</strong>. Each time you modify the repository whether by adding, modifying, or deleting, the revision number increase by one. So the repo revision number is an indication of the number of changes made to the repository since it was created.</p>
<h5 id="CreatingProject">Creating A New Project</h5>
<p>Now that our repo structure is ready lets create our first version controlled project. For sake of testing we will name the project <strong>sandbox-ws</strong>. The sandbox-ws project will be added to the trunk folder. We will use the same mkdir command</p>
<pre class="brush: plain;">
svn mkdir file:///c:/repo/trunk/sandbox-ws -m &quot;created sandbox-ws project&quot;
</pre>
<h5 id="CheckingOut">Checking Out a Project</h5>
<p>The figure below outlines the basic operations done on a subversion repository. First we create the repository, then initialize the project structure, then create one or more projects in the repository, and last but not least, the developers checks out a project, modifies it, and then commits the changes back to the repository so other developers can update their working copies to reflect those changes.</p>
<p>If sandbox-ws was a PHP project for example, then the working copy will be in your web server&#8217;s documents root, <strong>htdocs</strong> for example if you&#8217;re using <strong>Apache</strong>. But for sake of testing we will create our working copy on the <strong>Desktop</strong>.</p>
<p>To check out the sandbox-ws project run the following command(NOTE: I assume that you&#8217;ve changes the cmd path to your desktop):</p>
<pre class="brush: plain;">
svn co file:///c:/repo/trunk/sandbox-ws
</pre>
<p>The above command should result in the following output</p>
<pre class="brush: plain;">
Checked out revision 1.
</pre>
<p>Now we move to the sandbox-ws project:</p>
<pre class="brush: plain;">
cd sandbox-ws
</pre>
<h5 id="Adding">Adding Files to the Working Copy</h5>
<p>Now that we have checked out the sandbox-ws project, it&#8217;s time to add some files to it. We will start with a simple php file, see below</p>
<pre class="brush: plain;">
// index.php
&lt;?php echo 'Hello World!' ?&gt;
</pre>
<p>What we have done by adding a new file to the working copy is that we simply modified it. Lets see what subversion have to say now, run the following command from the sandbox-ws project folder</p>
<pre class="brush: plain;">
svn status
</pre>
<p>The above command output should be similar to the following:</p>
<pre class="brush: plain;">
?     index.php
</pre>
<p>The <strong>(?)</strong> next to the <strong>index.php</strong> file indicates that <strong>svn</strong> detected that the <strong>index.php</strong> status is unknown i.e. it&#8217;s new and has not been added to the working copy yet.</p>
<div class="note">
<p>Most new developers to subversion get confused at this point, adding a file/folder to a working copy doesn&#8217;t mean that <strong>svn</strong> will also add the new file/folder to the repository as well, that is done by committing the file/folder to the repository as we will see in the next section.</p>
</div>
<p>Since svn doesn&#8217;t know the status of the index.php file, we should add it to the working copy, to do this run the following command:</p>
<pre class="brush: plain;">
svn add index.php
</pre>
<p>The output of the following command should be similar to the following:</p>
<pre class="brush: plain;">
A      index.php
</pre>
<p>As you may have guessed, <strong>(A)</strong> means that the file has been added to the working copy, the next step would be committing the changes to the repository which would result in incrementing the repository revision number by one.</p>
<h5 id="Committing">Committing Changes</h5>
<p>After adding new the index.php file to the repository, we&#8217;ll want to commit it to the repository for other developers to be able to update their working copies and take advantage of our newly added file. To do so run the following command:</p>
<pre class="brush: plain;">
svn ci -m &quot;added index.php&quot;
</pre>
<p>The output of the following command should be similar to the following:</p>
<pre class="brush: plain;">
Adding         index.php
Transmitting file data .
Committed revision 2.
</pre>
<p>I think that the above doesn&#8217;t need any explanation, but the following does, run the following command:</p>
<pre class="brush: plain;">
svn info
</pre>
<p>The output of the following command should be similar to the following:</p>
<pre class="brush: plain;">
Path: .
URL: file:///c:/repo/trunk/sandbox-ws
Repository Root: file:///c:/repo
Repository UUID: 50729929-acbb-d647-b00b-4f3555a6f6a3
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: Sandbox
Last Changed Rev: 1
Last Changed Date: 2009-01-23 16:52:06 +0200 (Fri, 23 Jan 2009)
</pre>
<p>Of course some of the data displayed by the following command will differ between you and me but what is interesting about the command is that it indicates that the revision number of the working copy is less than the current revision number of the repository which is currently is 2. The reason of this is that after our commit the repository revision number as we have said increments by one but the our working copy is now out dated, we need to update it so the revision number of the working copy is similar to the repository. To do so run the following command:</p>
<pre class="brush: plain;">
svn update
</pre>
<p>The output of the following command should be similar to the following:</p>
<pre class="brush: plain;">
At revision 2.
</pre>
<p>I hope that this article successfully cleared what subversion is and how to start using it, in upcoming articles we will dive into more advanced topics.</p>
]]></content:encoded>
			<wfw:commentRss>http://sandbox-ws.com/subversion/introduction-to-subversion/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
