<?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>Steven She at woggie.net &#187; git</title>
	<atom:link href="http://www.woggie.net/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.woggie.net</link>
	<description>The life of a PhD Candidate in Software Engineering</description>
	<lastBuildDate>Wed, 16 Jun 2010 22:12:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Distributed Source Control using Mercurial</title>
		<link>http://www.woggie.net/2008/07/17/distributed-source-control-using-mercurial/</link>
		<comments>http://www.woggie.net/2008/07/17/distributed-source-control-using-mercurial/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 05:52:15 +0000</pubDate>
		<dc:creator>Steven She</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mercurial]]></category>

		<guid isPermaLink="false">http://www.woggie.net/?p=47</guid>
		<description><![CDATA[I&#8217;ve recently started to experiment with distributed source control systems for my personal repository. I had been using Subversion previously, but it had several issues with directories that bothered me. In addition, since my primary computer was a laptop, I also wanted to have full commit and change tracking when I was offline. So distributed [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently started to experiment with distributed source control systems for my personal repository. I had been using <a href="http://subversion.tigris.org">Subversion</a> previously, but it had several issues with directories that bothered me. In addition, since my primary computer was a laptop, I also wanted to have full commit and change tracking when I was offline.</p>
<p>So distributed source control systems seemed to fit the bill. I looked at two systems in particular, <a href="http://www.selenic.com/mercurial/">Mercurial</a> and <a href="http://git.or.cz">git</a>. Mercurial caught my eye because of its simplicity, and similarity with the traditional, centralized SCMs such as CVS and Subversion. However, I actually started using git first. The reason was that many open source projects had switched to git and I needed to compile several bleeding edge packages. So, I had no choice but to learn to use git. However, I couldn&#8217;t really wrap my head around it. While git is no doubt, a very powerful SCM, it was also a very complicated SCM. I took me a good hour or so before I understood how to track branches.</p>
<p>So, I settled for Mercurial. While I was worried that Mercurial was too immature, the fact that the <a href="http://www.mozilla.com">Mozilla</a> projects are <a href="http://weblogs.mozillazine.org/preed/2007/04/version_control_system_shootou_1.html">also using Mercurial</a> was very comforting.</p>
<p><span id="more-47"></span></p>
<h4>Usage, Tips and Tricks</h4>
<p>I will not describe the setup and typical usage of Mercurial, since there are plenty of <a href="http://blog.medallia.com/2007/02/a_guided_tour_of_mercurial.html">good tutorials</a> out there. What I will do, is highlight some of the features that have really caught my eye and I find indispensible now.</p>
<p>The first great feature of Mercurial is the <code>addremove</code> command, which removes deleted files and adds newly created files to the repository. The command also has an optional parameter which you can specify the directory to process. I typically use <code>.</code>, such that my next commit would only contain the changes that I&#8217;ve made in the current directory.</p>
<pre>hg addremove   #For the entire repository
hg addremove . #For the current directory</pre>
<p>Another nice feature of Mercurial is its ability to ignore certain files and file patterns specified using a <em>single</em> <code>.hgignore</code> file. This is very convenient, for excluding temporary files, such as the intermediary files that are left behind after compiling LaTeX source code. Mercurial supports two syntax types when specifying patterns in <code>.hgignore</code>, <em>glob</em> and <em>regex</em>. The glob syntax allows you to specify patterns using wildcards (*). I primarily use regex, since <a href="http://xkcd.com/208/">regular expressions are very powerful</a>.</p>
<p>Here are the contents of my current <code>.hgignore</code>:</p>
<pre>syntax: regexp
.*.swp
.*.swo
^results/.*
^projects/.*/bin/
^lab/[0-9][0-9](winter|spring|fall)/.+\.(log|glo|glg|gls|dvi|aux|bm|bbl|blg|brf|ist|lof|lot|out|toc|vrb|ps)</pre>
<p>After creating the <code>.hgignore</code> file, don&#8217;t forget to add it to the repository for tracking using:</p>
<pre>hg add .hgignore</pre>
<h4>Tracking Branches</h4>
<p>For those interested in how to track branches using git, here is the command that I used. the -b modifer creates a branch in the local repository. The checkout command further require the <code>origin/</code> prefix for branches. In addition, the <code>--track</code> modifier tracks the remote branch such that a future pull will retrieve updates from the branch.</p>
<p>Using Mercurial:</p>
<pre>hg co somebranch</pre>
<p>Using git:</p>
<pre>git checkout --track -b localbranch origin/somebranch</pre>
<p><strong>Update on git</strong><br />
Thanks to the comment by Jakub, tracking a remote branch is actually rather easy using the <code>git remote</code> command. Here is an example I had to do with retrieving a xf86-video-ati git repository.</p>
<pre>git remote add agd5f git://cgit.freedesktop.org/~agd5f/xf86-video-ati/</pre>
<p>To restrict the remote repository to a particular branch, use <code>-t</code> like the following:</p>
<pre>git remote add agd5f -t agd-powerplay git://cgit.freedesktop.org/~agd5f/xf86-video-ati/</pre>
<p>We can now fetch data from the remote repository using the command:</p>
<pre>git fetch agd5f</pre>
<p>We can list the branches that are present in our repository by executing the command. Note that the remote repository shows up just like a separate branch to our local repository:</p>
<pre>git branch -r</pre>
<p>Now, we can pull from this remote repository, and merge the changes from the branch <code>agd-powreplay</code>:</p>
<pre>git pull agd5f agd-powerplay</pre>
<h4>Restoring a Single File to a Previous Revision</h4>
<p>It seems that Mercurial is currently not able to checkout a single file or subdirectory. It is one of the &#8220;todo&#8221; items in <a href="http://code.google.com/soc/2008/hg/appinfo.html?csaid=B091D9B819911D09">their Google Summer of Code project</a> this year, so perhaps we&#8217;ll have this feature soon enough. However, this is rather inconvenient at the moment. A workaround for this issue is to use the <code>hg cat</code> command, to view a previous revision of a file. In my case, I had overwritten a file <code>applet.svg</code> with changes that I did not want to keep. To revert the file, I executed:</p>
<pre>hg cat applet.svg &gt; applet.svg</pre>
<h4>Tags</h4>
<p>In Mercurial, <a href="http://www.selenic.com/mercurial/wiki/index.cgi/Tag">tags</a> are simply aliases for changesets.</p>
<pre>hg checkout -r tagname</pre>
<p>git treats tags, branches and trunk/master as one and the same, in the sense that they are all <a href="http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#def_refspec">refspecs</a>. This is similar to Subversion&#8217;s model, however, tags and branches aren&#8217;t simply another directory in the repository. You have to add the <code>tags/</code> prefix when checking out a tag:</p>
<p>Using git:</p>
<pre>git checkout -b localtag tags/remotetag</pre>
<h4>Conclusions</h4>
<p>I am very happy with Mercurial. I ran into a very annoying issue with Mercurial early on, when I executed <code>hg fetch</code>, and it used my repository URI, along with my username and <em>password</em> as a commit message. However, luckily this issue was fixed in the Mercurial 1.0 release. Admittedly, I&#8217;ve only been using a single person Mercurial repository for the past couple months, so I haven&#8217;t really experienced a situation where I needed the full power of a SCM. However, Mercurial has been so far, been smooth sailing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.woggie.net/2008/07/17/distributed-source-control-using-mercurial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
