<?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>Jayway Team Blog &#187; git</title>
	<atom:link href="http://blog.jayway.com/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Finding with Git</title>
		<link>http://blog.jayway.com/2012/01/25/finding-with-git/</link>
		<comments>http://blog.jayway.com/2012/01/25/finding-with-git/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 16:23:07 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=11903</guid>
		<description><![CDATA[Git is an amazing version control system that never loses anything, but sometimes it can be hard to find out where things are. Most of the time it is going to be git log that is our friend, but not all the time. Where is my file? Sometimes you know that you have a file [...]]]></description>
			<content:encoded><![CDATA[<p>Git is an amazing version control system that never loses anything, but<br />
sometimes it can be hard to find out where things are. Most of the time<br />
it is going to be <code>git log</code> that is our friend, but not all the time.</p>
<h2>Where is my file?</h2>
<p>Sometimes you know that you have a file in your repository but, you<br />
don&#39;t know exactly where it is. <code>git ls-files</code> is the answer.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Find all files with the name security in the path.</font></i>
$ git ls-files <font color="#990000">|</font> grep security
lib/dynamo-db/security<font color="#990000">.</font>js
test/security-test<font color="#990000">.</font>js
</tt></pre>
<p>Obviously, you can use any particular <code>grep</code> options you prefer, like <code>-i</code><br />
to ignore case.</p>
<h2>In what files does <em>word</em> exist?</h2>
<p>If you want to find information inside files <code>git grep</code> is your friend.<br />
<code>git grep</code> works similar to a recursive grep <code>grep -r .</code> but it only<br />
searches files that are managed by git.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Find all lines matching *crypt* in current version.</font></i>
$ git grep crypt
lib/dynamo-db/security<font color="#990000">.</font>js<font color="#990000">:</font>var crypto <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'crypto'</font><font color="#990000">);</font>
lib/dynamo-db/security<font color="#990000">.</font>js<font color="#990000">:</font>   var hmac <font color="#990000">=</font> crypto<font color="#990000">.</font>createHmac<font color="#990000">(</font><font color="#FF0000">'sha256'</font><font color="#990000">,</font> key<font color="#990000">);</font>

<i><font color="#9A1900"># Also give me the line numbers</font></i>
 git grep -n crypt
lib/dynamo-db/security<font color="#990000">.</font>js<font color="#990000">:</font><font color="#993399">2</font><font color="#990000">:</font>var crypto <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'crypto'</font><font color="#990000">);</font>
lib/dynamo-db/security<font color="#990000">.</font>js<font color="#990000">:</font><font color="#993399">15</font><font color="#990000">:</font>   var hmac <font color="#990000">=</font> crypto<font color="#990000">.</font>createHmac<font color="#990000">(</font><font color="#FF0000">'sha256'</font><font color="#990000">,</font> key<font color="#990000">);</font>

<i><font color="#9A1900"># List only the file names</font></i>
 git grep -l crypt
lib/dynamo-db/security<font color="#990000">.</font>js

<i><font color="#9A1900"># Also list how many times (count) it matched.</font></i>
$ git grep -c crypt
lib/dynamo-db/security<font color="#990000">.</font>js<font color="#990000">:</font><font color="#993399">2</font>
</tt></pre>
<p>It is also possible to give versions to <code>grep</code> to find out what has<br />
changed between revisions.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Find all files with lines matching *type* in revisions `master` and `8f0fb7f`.</font></i>
git grep -l <b><font color="#0000FF">type</font></b>  master 8f0fb7f
master<font color="#990000">:</font>lib/dynamo-db/index<font color="#990000">.</font>js
master<font color="#990000">:</font>lib/dynamo-db/security<font color="#990000">.</font>js
master<font color="#990000">:</font>package<font color="#990000">.</font>json
8f0fb7f<font color="#990000">:</font>lib/dynamo-db/index<font color="#990000">.</font>js
8f0fb7f<font color="#990000">:</font>package<font color="#990000">.</font>json
</tt></pre>
<p>Maybe this is not that impressive. Most of the above can be accomplished<br />
with standard <code>grep</code>, <code>find</code>, <code>ack</code>, and friends. But Git is a version<br />
control system. How do I find out about things that happened in the past?</p>
<h2>Who deleted my file?</h2>
<p>You know how it is, you are working in some project and, your dog gets<br />
sick and you have to stay home from work, when you come back someone has<br />
deleted your file! Where is it and who did it? <code>git log</code> to the rescue.</p>
<p><code>git log</code> shows you the commit logs. It is your eye into the past.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># When (in what commit) was my file deleted?</font></i>
$ git log --diff-filter<font color="#990000">=</font>D -- test/create-table-test<font color="#990000">.</font>js
commit ba6c4d8bc165b8fb8208979c3e5513bd53477d51
Author<font color="#990000">:</font> Anders Janmyr <font color="#990000">&lt;</font>anders@janmyr<font color="#990000">.</font>com<font color="#990000">&gt;</font>
Date<font color="#990000">:</font>   Wed Jan <font color="#993399">25</font> <font color="#993399">09</font><font color="#990000">:</font><font color="#993399">46</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#993399">2012</font> <font color="#990000">+</font><font color="#993399">0100</font>

    Removed the stupid failing <b><font color="#0000FF">test</font></b><font color="#990000">.</font>
</tt></pre>
<p>Looks like I found the culprit, was I working from home? But is the file<br />
really deleted here. To get some more information about files add the<br />
<code>--summary</code> option.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># When (in what commit) was my file deleted?</font></i>
$ git log --diff-filter<font color="#990000">=</font>D --summary -- test/create-table-test<font color="#990000">.</font>js
commit ba6c4d8bc165b8fb8208979c3e5513bd53477d51
Author<font color="#990000">:</font> Anders Janmyr <font color="#990000">&lt;</font>anders@janmyr<font color="#990000">.</font>com<font color="#990000">&gt;</font>
Date<font color="#990000">:</font>   Wed Jan <font color="#993399">25</font> <font color="#993399">09</font><font color="#990000">:</font><font color="#993399">46</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#993399">2012</font> <font color="#990000">+</font><font color="#993399">0100</font>

    Removed the stupid failing <b><font color="#0000FF">test</font></b><font color="#990000">.</font>

 delete mode <font color="#993399">100644</font> test/create-table-test<font color="#990000">.</font>js
</tt></pre>
<p>Yes, it looks like the file is really deleted. Stupid bastard! Let me<br />
break this command down starting with the last command.</p>
<ul>
<li><code>test/create-table-test.js</code> - The filename has to be the relative path<br />
to the file (from your current directory).</li>
<li><code>--</code> - The double-dash is used to tell Git that this is not a branch<br />
or an option.</li>
<li><code>--summary</code> - Show me what files were deleted or added.<br />
<code>--name-status</code> is similar.</li>
<li><code>--diff-filter</code> - This is a real beauty, it allows me to limit the log<br />
to show me only the specified kind of change, in this case <code>D</code>, for<br />
Deleted. Other options are: Added (A), Copied (C), Modified (M) and Renamed (R)</li>
</ul>
<h2>When was a file added?</h2>
<p>This uses the same technique as above, but I will vary it since I don&#39;t<br />
want to type the full path of the file.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Find out when the integration tests where added.</font></i>
$ git log --diff-filter<font color="#990000">=</font>A --name-status <font color="#990000">|</font>grep -C <font color="#993399">6</font> integ
commit 09420cfea8c7b569cd47f690104750fec358a10a
Author<font color="#990000">:</font> Anders Janmyr <font color="#990000">&lt;</font>anders@janmyr<font color="#990000">.</font>com<font color="#990000">&gt;</font>
Date<font color="#990000">:</font>   Tue Jan <font color="#993399">24</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">23</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#993399">2012</font> <font color="#990000">+</font><font color="#993399">0100</font>

    Extracted integration <b><font color="#0000FF">test</font></b>

A	integration-test/sts-test<font color="#990000">.</font>js

commit 205db3965dec6c2c4c7b2bb75387a591d49e1951
Author<font color="#990000">:</font> Anders Janmyr <font color="#990000">&lt;</font>anders@janmyr<font color="#990000">.</font>com<font color="#990000">&gt;</font>
Date<font color="#990000">:</font>   Sat Jan <font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#993399">2012</font> <font color="#990000">+</font><font color="#993399">0100</font>
</tt></pre>
<p>As you can see here I am using <code>--name-status</code> as a variation on<br />
<code>--summary</code>, it uses the same notation as the <code>--diff-filter</code>.</p>
<p>I am using <code>grep -C 6</code> to get some context around the found element, in<br />
this case six lines before and after the match. Very useful!</p>
<h2>Who changed that line?</h2>
<p>As you probably know it is to see who has done something in a file by<br />
using <code>git blame</code></p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git blame test/security-test<font color="#990000">.</font>js
205db396 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">1</font><font color="#990000">)</font> var vows <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'vows'</font><font color="#990000">),</font>
205db396 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">2</font><font color="#990000">)</font>     assert <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'assert'</font><font color="#990000">);</font>
205db396 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">3</font><font color="#990000">)</font>
09420cfe <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">24</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">23</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">4</font><font color="#990000">)</font> var access <font color="#990000">=</font> <font color="#FF0000">'access'</font><font color="#990000">;</font>
09420cfe <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">24</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">23</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">5</font><font color="#990000">)</font> var secret <font color="#990000">=</font> <font color="#FF0000">'secret'</font><font color="#990000">;</font>
90b65208 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">11</font><font color="#990000">:</font><font color="#993399">58</font><font color="#990000">:</font><font color="#993399">21</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">6</font><font color="#990000">)</font>
205db396 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">7</font><font color="#990000">)</font> var security <font color="#990000">=</font> new Security<font color="#990000">(</font>{
90b65208 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">11</font><font color="#990000">:</font><font color="#993399">58</font><font color="#990000">:</font><font color="#993399">21</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">8</font><font color="#990000">)</font>   access<font color="#990000">:</font> access<font color="#990000">,</font>
90b65208 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">11</font><font color="#990000">:</font><font color="#993399">58</font><font color="#990000">:</font><font color="#993399">21</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">9</font><font color="#990000">)</font>   secret<font color="#990000">:</font> secret
205db396 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">10</font><font color="#990000">:</font><font color="#993399">03</font><font color="#990000">:</font><font color="#993399">59</font> <font color="#990000">+</font><font color="#993399">0100</font> <font color="#993399">10</font><font color="#990000">)</font> }<font color="#990000">);</font>
<font color="#990000">...</font>
</tt></pre>
<p>Every line gets annotated with the commit who introduced it and by whom.<br />
Very helpful.</p>
<h2>Who deleted that line?</h2>
<p>Another feature, which is not as well known, is <code>git blame --reverse</code>.<br />
It allows you to see the file as it was before, annotated to show you<br />
where it has been changed.</p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Check the what lines have been changed since the last 6 commits.</font></i>
$ git blame --reverse head<font color="#990000">~</font><font color="#993399">6</font><font color="#990000">..</font>head security-test<font color="#990000">.</font>js
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">1</font><font color="#990000">)</font> var vows <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'vows'</font><font color="#990000">),</font>
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">2</font><font color="#990000">)</font>     assert <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'assert'</font><font color="#990000">);</font>
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">3</font><font color="#990000">)</font>
093c13e9 <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">24</font> <font color="#993399">17</font><font color="#990000">:</font><font color="#993399">26</font><font color="#990000">:</font><font color="#993399">09</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">4</font><font color="#990000">)</font> var Security <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'dynamo-db'</font><font color="#990000">).</font>Security<font color="#990000">;</font>
ba6c4d8b <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">09</font><font color="#990000">:</font><font color="#993399">46</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">5</font><font color="#990000">)</font>
<font color="#990000">^</font>b96c68b <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">12</font><font color="#990000">:</font><font color="#993399">33</font><font color="#990000">:</font><font color="#993399">50</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">6</font><font color="#990000">)</font> var access <font color="#990000">=</font> process<font color="#990000">.</font>env<font color="#990000">[</font><font color="#FF0000">'S3_KEY'</font><font color="#990000">];</font>
<font color="#990000">^</font>b96c68b <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">21</font> <font color="#993399">12</font><font color="#990000">:</font><font color="#993399">33</font><font color="#990000">:</font><font color="#993399">50</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">7</font><font color="#990000">)</font> var secret <font color="#990000">=</font> process<font color="#990000">.</font>env<font color="#990000">[</font><font color="#FF0000">'S3_SECRET'</font><font color="#990000">];</font>
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">8</font><font color="#990000">)</font>
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font>  <font color="#993399">9</font><font color="#990000">)</font> var security <font color="#990000">=</font> new Security<font color="#990000">(</font>{
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font> <font color="#993399">10</font><font color="#990000">)</font>   access<font color="#990000">:</font> access<font color="#990000">,</font>
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font> <font color="#993399">11</font><font color="#990000">)</font>   secret<font color="#990000">:</font> secret
558b8e7f <font color="#990000">(</font>Anders Janmyr <font color="#993399">2012</font>-<font color="#993399">01</font>-<font color="#993399">25</font> <font color="#993399">16</font><font color="#990000">:</font><font color="#993399">53</font><font color="#990000">:</font><font color="#993399">52</font> <font color="#990000">+</font><font color="#993399">0100</font> <font color="#993399">12</font><font color="#990000">)</font> }<font color="#990000">);</font>
</tt></pre>
<p>In the output you can see that most of the lines are still the same at<br />
HEAD (558b8e7f). But the fourth and fifth line <code>093c13e9</code> and <code>ba6c4d8b</code><br />
don&#39;t exist anymore. And the sixth and seventh lines <code>^b96c68b</code> have<br />
been changed after this commit.</p>
<h2>What commits contain the string?</h2>
<p>Another thing I find very useful is to find out when certain words or<br />
sentences are removed or added. For this you can use <code>git log -S&lt;string&gt;</code> or<br />
<code>git log -G&lt;regex&gt;</code></p>
<p><!-- Generator: GNU source-highlight 3.1.5<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Find commits that modified the string aws and display the full diff.</font></i>
$ git log -Saws --diff-filter<font color="#990000">=</font>M --patch
commit b96c68b839f204b310b79570bc3d27dc93cff588
Author<font color="#990000">:</font> Anders Janmyr <font color="#990000">&lt;</font>anders@janmyr<font color="#990000">.</font>com<font color="#990000">&gt;</font>
Date<font color="#990000">:</font>   Sat Jan <font color="#993399">21</font> <font color="#993399">12</font><font color="#990000">:</font><font color="#993399">33</font><font color="#990000">:</font><font color="#993399">50</font> <font color="#993399">2012</font> <font color="#990000">+</font><font color="#993399">0100</font>

    We have a valid request<font color="#990000">,</font> tjohoo

diff --git a/lib/dynamo-db/security<font color="#990000">.</font>js b/lib/dynamo-db/security<font color="#990000">.</font>js
index bee6936<font color="#990000">..</font><font color="#993399">8471527</font> <font color="#993399">100644</font>
--- a/lib/dynamo-db/security<font color="#990000">.</font>js
<font color="#990000">+++</font> b/lib/dynamo-db/security<font color="#990000">.</font>js
@@ -<font color="#993399">2</font><font color="#990000">,</font><font color="#993399">6</font> <font color="#990000">+</font><font color="#993399">2</font><font color="#990000">,</font><font color="#993399">7</font> @@
 var crypto <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'crypto'</font><font color="#990000">);</font>
 var _ <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'underscore'</font><font color="#990000">);</font>
 var request <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">"request"</font><font color="#990000">);</font>
<font color="#990000">+</font>var xml2js <font color="#990000">=</font> require<font color="#990000">(</font><font color="#FF0000">'xml2js'</font><font color="#990000">);</font>

 <b><font color="#000000">function Security</font></b><font color="#990000">(</font>options<font color="#990000">)</font> {
   this<font color="#990000">.</font>options <font color="#990000">=</font> options<font color="#990000">;</font>
@@ -<font color="#993399">23</font><font color="#990000">,</font><font color="#993399">7</font> <font color="#990000">+</font><font color="#993399">24</font><font color="#990000">,</font><font color="#993399">7</font> @@ mod<font color="#990000">.</font>timestamp <font color="#990000">=</font> <b><font color="#000000">function()</font></b> {
 mod<font color="#990000">.</font>defaultParams <font color="#990000">=</font> <b><font color="#000000">function()</font></b> {
   <b><font color="#0000FF">return</font></b> {
     AWSAccessKeyId<font color="#990000">:</font> this<font color="#990000">.</font>options<font color="#990000">.</font>access<font color="#990000">,</font>
-    Version<font color="#990000">:</font> <font color="#FF0000">'2010-05-08'</font><font color="#990000">,</font>
<font color="#990000">+</font>    Version<font color="#990000">:</font> <font color="#FF0000">'2011-06-15'</font><font color="#990000">,</font>
     Timestamp<font color="#990000">:</font> this<font color="#990000">.</font><b><font color="#000000">timestamp()</font></b><font color="#990000">,</font>
     SignatureVersion<font color="#990000">:</font> <font color="#993399">2</font><font color="#990000">,</font>
     SignatureMethod<font color="#990000">:</font> <font color="#FF0000">'HmacSHA256'</font>
@@ -<font color="#993399">57</font><font color="#990000">,</font><font color="#993399">9</font> <font color="#990000">+</font><font color="#993399">58</font><font color="#990000">,</font><font color="#993399">10</font> @@ mod<font color="#990000">.</font>url <font color="#990000">=</font> function<font color="#990000">(</font>host<font color="#990000">,</font> path<font color="#990000">,</font> params<font color="#990000">)</font> {

 mod<font color="#990000">.</font>makeRequest <font color="#990000">=</font> function<font color="#990000">(</font>method<font color="#990000">,</font> host<font color="#990000">,</font> path<font color="#990000">,</font> params<font color="#990000">,</font> callback<font color="#990000">)</font> {
   var extParams <font color="#990000">=</font> _<font color="#990000">.</font>extend<font color="#990000">(</font>{}<font color="#990000">,</font> this<font color="#990000">.</font><b><font color="#000000">defaultParams()</font></b><font color="#990000">,</font> params<font color="#990000">);</font>
-  var signedParams <font color="#990000">=</font> this<font color="#990000">.</font>signedParams<font color="#990000">(</font><font color="#FF0000">'GET'</font><font color="#990000">,</font> <font color="#FF0000">'iam.amazonaws.com'</font><font color="#990000">,</font> <font color="#FF0000">'/'</font><font color="#990000">,</font> extParams<font color="#990000">);</font>
-  console<font color="#990000">.</font>log<font color="#990000">(</font>extParams<font color="#990000">,</font>signedParams<font color="#990000">);</font>
-  <b><font color="#0000FF">return</font></b> request<font color="#990000">(</font>{ method<font color="#990000">:</font> method<font color="#990000">,</font> url<font color="#990000">:</font> this<font color="#990000">.</font>url<font color="#990000">(</font>host<font color="#990000">,</font> path<font color="#990000">,</font> signedParams<font color="#990000">)</font> }<font color="#990000">,</font>
<font color="#990000">+</font>  var signedParams <font color="#990000">=</font> this<font color="#990000">.</font>signedParams<font color="#990000">(</font>method<font color="#990000">,</font> host<font color="#990000">,</font> path<font color="#990000">,</font> extParams<font color="#990000">);</font>
<font color="#990000">+</font>  var url <font color="#990000">=</font> this<font color="#990000">.</font>url<font color="#990000">(</font>host<font color="#990000">,</font> path<font color="#990000">,</font> signedParams<font color="#990000">);</font>
<font color="#990000">+</font>  console<font color="#990000">.</font>log<font color="#990000">(</font>url<font color="#990000">,</font>signedParams<font color="#990000">);</font>
<font color="#990000">+</font>  <b><font color="#0000FF">return</font></b> request<font color="#990000">(</font>{ method<font color="#990000">:</font> method<font color="#990000">,</font> url<font color="#990000">:</font> url }<font color="#990000">,</font>
<font color="#990000">...</font>
</tt></pre>
<p>That&#39;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2012/01/25/finding-with-git/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Deploying a Clojure web app on Heroku</title>
		<link>http://blog.jayway.com/2011/06/13/deploying-a-clojure-web-app-on-heroku/</link>
		<comments>http://blog.jayway.com/2011/06/13/deploying-a-clojure-web-app-on-heroku/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 13:56:05 +0000</pubDate>
		<dc:creator>Ulrik Sandberg</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[heroku]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=8712</guid>
		<description><![CDATA[<p><a href="http://www.heroku.com/">Heroku</a> is a cloud application platform for Ruby/Rails and Node.js. However, the <a href="http://devcenter.heroku.com/articles/cedar">Cedar stack</a> on Heroku makes it possible to deploy other types of applications. In this blog entry, I will first describe how to write a simple <a href="http://clojure.org">Clojure</a> web app using the <a href="https://github.com/mmcgrana/ring">Ring library</a> and the build tool <a href="https://github.com/technomancy/leiningen">Leiningen</a>. Then I will show how to deploy this Clojure web app on Heroku, using nothing but Git. I will make a change and see how to deploy that. I will also show how to easily roll back to a previous release.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.heroku.com/">Heroku</a> is a cloud application platform for Ruby/Rails and Node.js. However, the <a href="http://devcenter.heroku.com/articles/cedar">Cedar stack</a> on Heroku makes it possible to deploy other types of applications. In this blog entry, I will first describe how to write a simple <a href="http://clojure.org">Clojure</a> web app using the <a href="https://github.com/mmcgrana/ring">Ring library</a> and the build tool <a href="https://github.com/technomancy/leiningen">Leiningen</a>. Then I will show how to deploy this Clojure web app on Heroku, using nothing but Git. I will make a change and see how to deploy that. I will also show how to easily roll back to a previous release.</p>
<h2>Clojure maps</h2>
<p>A map is a data structure that associates keys to values. Maps are very important in Clojure, because they are used to store entity data, much like custom classes with fields and setters/getters are used in traditional object-oriented languages like Java. In the Java world, we have java.util.Map. They are somewhat cumbersome to work with, mostly due to the static, generic typing, but also because there is no literal map syntax, plus the fact that you can't initialize it with elements. You must first create it, then mutate it:</p>
<pre class="brush: java;gutter: false;">
import java.util.Map;
import java.util.HashMap;

Map&lt;String,Object&gt; map = new HashMap&lt;String,Object&gt;();
map.put("somekey", "somevalue");
</pre>
<p>Clojure maps, on the other hand, have a very concise literal syntax. Zero or more key-value pairs between curly braces. That's it.</p>
<pre class="brush: clojure;gutter: false;">
(def map {:somekey "somevalue"})
</pre>
<p>The key <code>:somekey</code> in the map above is a Clojure <code>keyword</code>. Keywords are symbolic identifiers that always evaluate to themselves, and they have a very fast equality check. For those reasons (and others, as we will see), keywords are often used, rather than strings, as keys in maps.</p>
<p>A Clojure map is not only a data structure, it is also a function. When a map is called with a key, it will return the corresponding value (or nil if no key was found). It can look like this when testing it from the <a href="http://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a>:</p>
<pre class="brush: clojure;gutter: false;">
user&gt; (def animal {:species :lion, :name "Leo", :age 3})
user&gt; (animal :name)
"Leo"
</pre>
<p>In fact, keywords are functions too. When a keyword is called with a map as argument, it will look itself up in the map and return the matching value:</p>
<pre class="brush: clojure;gutter: false;">
user&gt; (:name animal)
"Leo"
</pre>
<p>This form is more common in idiomatic Clojure.</p>
<h2>The Ring library</h2>
<p>Ring is a Clojure web applications library inspired by Ruby's Rack. Ring abstracts the <span class="caps">HTTP</span> request and response as maps, and expects handlers to be functions that take a map as argument and returns a map. The returned map is transformed by Ring into a <span class="caps">HTTP</span> response, which is sent back to the caller. This is a simple, but powerful abstraction. It means that web handlers can be written as regular functions, which can be tested in isolation. Web libraries like <a href="https://github.com/weavejester/compojure/wiki">Compojure</a> build on top of the Ring abstraction and provide more high-level constructs, like routing. In order to not complicate this example, however, we will stick to plain Ring.</p>
<p>Let's say that we have a <span class="caps">HTTP</span> request that looks like this:</p>
<pre class="brush: plain;gutter: false;">
GET /welcome HTTP/1.1
HOST: www.sayhello.com
</pre>
<p>Ring transforms this into a Clojure map that looks like this:</p>
<pre class="brush: clojure;">
{:protocol        :http
 :request-method  :get
 :uri             "/welcome"
 :server-name     "www.sayhello.com"}
</pre>
<p>Let's further assume that we want to generate a corresponding <span class="caps">HTTP</span> response:</p>
<pre class="brush: plain;gutter: false;">
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 11

Hello world
</pre>
<p>In order to produce that <span class="caps">HTTP</span> response, Ring expects this map:</p>
<pre class="brush: clojure;">
{:status 200
 :headers
    {"Content-Type" "text/plain"
     "Content-Length" 11}
 :body "Hello world"}
</pre>
<p>So all we need to do is to provide a function that returns the above map, like this:</p>
<pre class="brush: clojure;highlight:1">
(defn app [req]
  {:status 200
   :headers
      {"Content-Type" "text/plain"
       "Content-Length" 11}
   :body "Hello world"})
</pre>
<p>Ring provides a <code>response</code> convenience function that returns a skeletal response map with status 200, no headers, and the given argument as body:</p>
<pre class="brush: clojure;highlight:[1,3]">
(use 'ring.util.response)
(defn app [req]
  (response "Hello world"))
</pre>
<p>We'll use the <code>response</code> function in our example later.</p>
<h2>Leiningen</h2>
<p>In order to manage our dependencies, we will use the <a href="https://github.com/technomancy/leiningen">Leiningen</a> build tool. The simplest way to install it is to download the <a href="https://github.com/technomancy/leiningen/raw/stable/bin/lein">stable release</a> of the script and place it somewhere in the <span class="caps">PATH</span>, like ~/bin. Then run <code>lein self-install</code>:</p>
<pre class="brush: plain;gutter: false;">
$ lein self-install
Downloading Leiningen now...
...

$ lein version
Leiningen 1.5.2 on Java 1.6.0_24 Java HotSpot(TM) 64-Bit Server VM
</pre>
<h2>Building the web application</h2>
<p>We create a new project and go there:</p>
<pre class="brush: plain;gutter: false;">
$ lein new cljheroku
$ cd cljheroku
</pre>
<p>The newly created directory contains the following files:</p>
<pre class="brush: plain;gutter: false;">
cljheroku/
├── README
├── project.clj
├── src
│   └── cljheroku
│       └── core.clj
└── test
    └── cljheroku
        └── test
            └── core.clj
</pre>
<p>First we need to create a Procfile for Heroku:</p>
<pre class="brush: plain;gutter: false;">
$ echo "web: lein run -m cljheroku.core" &gt; Procfile
</pre>
<p>This will have Leiningen start the web application by running the function called <code>-main</code> in the namespace cljheroku.core, ie the file <code>src/cljheroku/core.clj</code>. We'll change that file to contain this:</p>
<pre class="brush: clojure;">
(ns cljheroku.core
  (:use ring.util.response
        ring.adapter.jetty))

(defn app [req]
  (response "Hello World"))

(defn -main []
  (let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
    (run-jetty app {:port port})))
</pre>
<p>Let's look at this code in more detail. We begin with the first chunk:</p>
<pre class="brush: clojure; first-line: 01;">
(ns cljheroku.core
  (:use ring.util.response
        ring.adapter.jetty))
</pre>
<p>The <a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/ns">ns macro</a> will create a namespace cljheroku.core and load all functions in the namespaces ring.util.response and ring.adapter.jetty. Since we used <code>:use</code> and not <code>:require</code>, these functions can be referenced by name, without any prefix or namespace qualifier. This enables us to write <code>(response ...)</code> instead of <code>(ring.util.response/response ...)</code>.</p>
<p>Then we define our Ring handler called <code>app</code>.</p>
<pre class="brush: clojure; first-line: 05;">
(defn app [req]
  (response "Hello World"))
</pre>
<p>As you can see, it's just a regular function that takes one argument: a <span class="caps">HTTP</span> request map, and returns the result of the response function: a <span class="caps">HTTP</span> response map. If we wanted to set the Content-Type header, we could use the <code>content-type</code> function, another function from ring.util.response. Instead of <code>(response "Hello world")</code>, we would pass the response through the <code>content-type</code> function: <code>(content-type (response "Hello world") "text/plain")</code>. But here we will just use <code>response</code>.</p>
<p>Finally we specify a <code>-main</code> function.</p>
<pre class="brush: clojure; first-line: 8;">
(defn -main []
  (let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
    (run-jetty app {:port port})))
</pre>
<p>It will serve the same purpose as the Java main method, namely provide an entry point from the outside world. It gets the value of the <span class="caps">PORT</span> environment variable, or uses 8080 as default. It can be enlightening to analyze that part in detail. <code>(System/getenv)</code> is simply Clojure's way of calling Java's static method <code>System.getenv()</code>, which returns a java.util.Map. The <code>get</code> function takes a map (yes, it works with Java maps too), a key and a default value, and returns the matching value. So, <code>(get (System/getenv) "PORT" "8080")</code> will get the <span class="caps">PORT</span> variable from the environment, and if there is no <span class="caps">PORT</span> set there, it will return "8080". The resulting string value of the port is parsed into an integer, and is stored as the local variable <code>port</code>. This value is then passed in to the Jetty adapter as part of a configuration map. All this in two lines. If you're not used to Clojure's lack of ceremony, you might find it overwhelming. I personally find it refreshingly to-the-point.</p>
<p>OK, that was the source code for our handler. We now need to adjust the project.clj file slightly, and provide a dependency to Ring. We'll also add an exclusion of a duplicate dependency that Jetty has. Here is the resulting project.clj:</p>
<pre class="brush: clojure;">
(defproject cljheroku "1.0.0-SNAPSHOT"
  :description "Example Ring app running on Heroku"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [ring/ring-core "0.3.8"]
                 [ring/ring-jetty-adapter "0.3.8"]]
  :exclusions [org.mortbay.jetty/servlet-api])
</pre>
<p>Before we do anything else, though, we should add this baby to Git:</p>
<pre class="brush: plain;gutter: false;">
$ git init
Initialized empty Git repository in /Users/john/Source/cljheroku/.git/

$ git add .

$ git commit -m "Initial commit"
</pre>
<p>We should probably push this to a maintained repository somewhere, but for our purposes, we have now stored this in Git.</p>
<h2>Testing locally</h2>
<p>Before we test it, we will ask Leiningen to retrieve the dependencies:</p>
<pre class="brush: plain;gutter: false;">
$ lein deps
</pre>
<p>The lib directory now contains a list of jars that we need. Leiningen will make sure they all get on the classpath without you ever having to see it. You <em>can</em> ask Leiningen for the classpath, though, should you really like to see it:</p>
<pre class="brush: plain;gutter: false;">
$ lein classpath
</pre>
<p>You can also have Leiningen create a pom file for you, which can be handy if you need to look at the dependency:tree, import the project into an <span class="caps">IDE</span> that only knows Maven; things like that:</p>
<pre class="brush: plain;gutter: false;">
$ lein pom
</pre>
<p>Anyway, we can now start this web application using the same command as we placed in the Procfile for Heroku. It will start Clojure with the correct classpath, find and make available the given namespace (cljheroku.core), and call its <code>-main</code> function with any given arguments (none, in our case):</p>
<pre class="brush: plain;gutter: false;">
$ lein run -m cljheroku.core
2011-06-12 18:41:24.927:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2011-06-12 18:41:24.928:INFO::jetty-6.1.26
2011-06-12 18:41:24.959:INFO::Started SocketConnector@0.0.0.0:8080
</pre>
<p>Browsing to localhost:8080 shows a page with "Hello world" on it. Good. It works.</p>
<p>We now change the handler function to instead respond with, say, "Hello everyone" and save it. When we reload the page, the new message appears. Excellent. It reloads automatically.</p>
<p>OK. We're happy with our web application and want to deploy it into the cloud. What do we do?</p>
<h2>Deploying on Heroku</h2>
<p>Heroku is, as I mentioned at the beginning, mainly a Ruby application platform. The command line tool for working with Heroku is a Ruby Gem. We first need to install Ruby and RubyGems. Assuming that has been done, we need to get the heroku gem:</p>
<pre class="brush: plain;gutter: false;">
$ sudo gem install heroku
</pre>
<p>Now we can create an app on the Cedar stack:</p>
<pre class="brush: plain;gutter: false;">
$ heroku create --stack cedar
Enter your Heroku credentials.
Email: john.doe@example.com
Password:
Found existing public key: /Users/john/.ssh/id_rsa.pub
Would you like to associate it with your Heroku account? [Yn]
Uploading ssh public key /Users/john/.ssh/id_rsa.pub
Creating furious-sword-794... done, stack is cedar
http://furious-sword-794.herokuapp.com/ | git@heroku.com:furious-sword-794.git
Git remote heroku added
</pre>
<p>We can list the remote repositories to see what the last sentence above meant:</p>
<pre class="brush: plain;gutter: false;">
$ git remote -v
heroku	git@heroku.com:furious-sword-794.git (fetch)
heroku	git@heroku.com:furious-sword-794.git (push)
</pre>
<p>And finally, in order to deploy our first verison of the web app, we push everything to heroku:</p>
<pre class="brush: plain;gutter: false;">
$ git push heroku master
The authenticity of host 'heroku.com (50.19.85.156)' can't be established.
RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'heroku.com,50.19.85.156' (RSA) to the list of known hosts.
Counting objects: 13, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (13/13), 1.27 KiB, done.
Total 13 (delta 0), reused 0 (delta 0)

-----&gt; Heroku receiving push
-----&gt; Clojure app detected
-----&gt; Installing Leiningen
       Downloading: leiningen-1.5.2-standalone.jar
       Writing: lein script
-----&gt; Installing dependencies with Leiningen
       Running: lein deps :skip-dev
       Downloading: org/clojure/clojure/1.2.1/clojure-1.2.1.pom from central
       Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.pom from clojars
       ...
       Copying 10 files to /tmp/build_19juox87ngduz/lib
-----&gt; Discovering process types
       Procfile declares types -&gt; web
-----&gt; Compiled slug size is 11.0MB
-----&gt; Launching... done, v4
       http://furious-sword-794.herokuapp.com deployed to Heroku

To git@heroku.com:furious-sword-794.git
 * [new branch]      master -&gt; master
</pre>
<p>We browse to http://furious-sword-794.herokuapp.com, and we see the text "Hello world" (if you remembered to change back from "Hello everyone"). Now we make a small change:</p>
<pre class="brush: plain;gutter: false;">
-  (response "Hello World"))
+  (response "Hello World, I tell you!"))
</pre>
<p>All we need to do to deploy the change is to commit it, and then push to heroku:</p>
<pre class="brush: plain;gutter: false;">
$ git ci -a
$ git push heroku master
</pre>
<p>When we reload the page, the new text is there.</p>
<h2>Roll back to previous release</h2>
<p>We can list the releases that have been pushed:</p>
<pre class="brush: plain;gutter: false;">
$ heroku releases
Rel   Change                          By                    When
----  ----------------------          ----------            ----------
v5    Deploy 34516b0                  john.doe@examp..  3 minutes ago
v4    Deploy e471ca1                  john.doe@examp..  5 minutes ago
</pre>
<p>Let's say there was a problem with the release that was just deployed, and we want to roll back. With Heroku, it's trivial to roll back to the previous release:</p>
<pre class="brush: plain;gutter: false;">
$ heroku rollback
Rolled back to v4
</pre>
<p>When we're done with this web app completely, we can destroy it like this:</p>
<pre class="brush: plain;gutter: false;">
$ heroku apps:destroy
</pre>
<p>It's even possible to roll back to earlier releases, but I won't show that here. This concludes the Clojure-on-Heroku guide. Thank you for your time.</p>
<h2>References</h2>
<ol>
<li>Heroku: <a href="http://www.heroku.com/">http://www.heroku.com/</a></li>
<li>Clojure: <a href="http://clojure.org/">http://clojure.org/</a></li>
<li>Ring library: <a href="https://github.com/mmcgrana/ring">https://github.com/mmcgrana/ring</a></li>
<li>Leiningen: <a href="https://github.com/technomancy/leiningen">https://github.com/technomancy/leiningen</a></li>
<li>Compojure: <a href="https://github.com/weavejester/compojure/wiki">https://github.com/weavejester/compojure/wiki</a></li>
<li><a href="http://flightcaster.com/">FlightCaster</a> uses Clojure and Heroku: <a href="http://www.infoq.com/articles/flightcaster-clojure-rails">http://www.infoq.com/articles/flightcaster-clojure-rails</a></li>
<li>I got the idea for this blog from this Gist: <a href="https://gist.github.com/1001206">https://gist.github.com/1001206</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/06/13/deploying-a-clojure-web-app-on-heroku/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Git with Subversion</title>
		<link>http://blog.jayway.com/2010/09/02/using-git-with-subversion/</link>
		<comments>http://blog.jayway.com/2010/09/02/using-git-with-subversion/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 07:45:26 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=6260</guid>
		<description><![CDATA[I had the unfortunate experience of having to use Subversion again after using Git for a long time. It is amazing how fast I can forget. After renaming a directory at the prompt, and the agony that goes with it, I decided to switch back to Git. $ mv requester sampler # svn agony after [...]]]></description>
			<content:encoded><![CDATA[<p>I had the unfortunate experience of having to use Subversion again after using Git for a long time. It is amazing how fast I can forget. After renaming a directory at the prompt, and the agony that goes with it, I decided to switch back to Git.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mv requester sampler
<i><font color="#9A1900"># svn agony after renaming a directory</font></i>
$ svn st
<font color="#990000">?</font>       sampler
<font color="#990000">!</font>       requester
<font color="#990000">!</font>       requester<font color="#990000">.</font>rb
A       sampler<font color="#990000">.</font>rb

</tt></pre>
<p>The tool to use when using Git with Subversion is, of course, <code>git svn</code>.</p>
<p><code>git svn</code> works very well as long as you remember that <em>Subversion is not Git</em>. It does not handle merging well, and it will bite you if you don't respect that. So what does this actually mean? It means:</p>
<h2>Always keep the Git master in sync with Subversion</h2>
<p>To do this you have two commands you can use.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Rebases the commits from the upstream Subversion server with your local master.</font></i>
$ git svn rebase

</tt></pre>
<p>You should only <code>git svn rebase</code> in your Git master, and you should <strong>ALWAYS</strong> do it before you <code>git svn dcommit</code> anything to the subversion repository. <code>git svn rebase</code> keeps the upstream subversion in sync with your local master by pulling down the changes, kind of like <code>svn update</code>.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Commits the changes you have in your local master to the upstream Subversion server.</font></i>
$ git svn dcommit

</tt></pre>
<p>When you have changes ready to commit, you commit them to subversion with <code>git svn dcommit</code>. You should <strong>ALWAYS</strong> <code>git svn rebase</code> before you do the update, or it will fail.</p>
<p>That's it! As long as you follow these two simple rules, your life with <code>git svn</code> will be easy. If you forget to follow them, you will be bitten. When you get bitten, the cool thing about Git is that even if you screw up, it is always possible to sort it out.</p>
<p>It that was all there was to it, there would be no reason to use Git instead of Subversion. Git really shines when it comes to branching and merging. You may create as many local branches as you like with <code>git branch branch_name</code> or <code>git checkout -b branch_name</code>. You can hack around in these local branches as much as you want and merge them together. But, before you merge them into the master branch, <strong>you must rebase with master! Not merge, rebase!</strong> Rebase means replay the commits on top of the named branch. It creates new commits, the same content, but with a different SHA-1.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Example session</font></i>

<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout -b dev
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...</font>
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git commit -am <font color="#FF0000">'Commit the changes'</font> 

<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout -b bugfix
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...,</font> <b><font color="#0000FF">done</font></b>

<font color="#990000">(</font>bugfix<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout bugfix
$ git rebase master
<font color="#990000">(</font>bugfix<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git merge --ff bugfix <i><font color="#9A1900"># --ff only fast-forwards, merges that don't need to merge. </font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit
<font color="#990000">(</font>master<font color="#990000">)</font>$ git branch -D bugfix <i><font color="#9A1900"># delete the branch it is not needed anymore</font></i>

<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout dev
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...,</font> <b><font color="#0000FF">done</font></b>

<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout dev
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git rebase master
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git merge --ff dev <i><font color="#9A1900"># --ff only fast-forwards, merges that don't need to merge.</font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit

</tt></pre>
<p>Another thing to be aware of is that <code>git svn dcommit</code> creates an extra commit, so even if you haven't changed anything in the master you need to rebase the local branch with the master. This is only needed if you don't delete the branches after you are done with a commit.</p>
<p>In the example above, I ended with a <code>git svn dcommit</code> and I didn't remove the <code>dev</code> branch.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit <i><font color="#9A1900"># from above</font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git co dev
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git rebase master <i><font color="#9A1900"># rebases the extra commit created by git svn dcommit</font></i>

</tt></pre>
<p>If you forget to rebase or something else happens that hinders a clean merge into the master. You can always back out of it with <code>git reset --hard</code>.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit
<font color="#990000">...</font> failed miserably<font color="#990000">,</font> because I failed to git svn rebase<font color="#990000">,</font> bollocks<font color="#990000">!</font>
<font color="#990000">(</font>aa<font color="#990000">..</font>88dd<font color="#990000">|</font>MERGING<font color="#990000">)</font>$ git reset --hard
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit <i><font color="#9A1900"># Nice and clean commit</font></i>

</tt></pre>
<p>To get started you need to clone a subversion repository.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git svn clone http<font color="#990000">:</font>//svn<font color="#990000">.</font>example<font color="#990000">.</font>com/project/trunk
$ cd trunk
<font color="#990000">(</font>master<font color="#990000">)</font>$ git <font color="#990000">...</font>

</tt></pre>
<p>Now, is a good time to start using Git. Get yourself anything by Scott Chacon, such as the <a href="http://www.amazon.com/Pro-Git-Scott-Chacon/dp/1430218339?tag=thtasta-20">book</a> or the <a href="http://www.gitcasts.com/">screencasts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/09/02/using-git-with-subversion/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Under the Hood of &#8216;git clone&#8217;</title>
		<link>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/</link>
		<comments>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 05:02:08 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[version controlling]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2283</guid>
		<description><![CDATA[When you clone a git repository, everything is automatically setup to allow you to fetch, pull, push to and from the remote repository, origin. But what is really going on? git remote is configured with a few lines of configuration in the config file inside the .git/ directory. Here&#8217;s how it works: Create a new [...]]]></description>
			<content:encoded><![CDATA[<div id="mycontent">
<div class="paragraph">
<p>When you clone a git repository, everything is automatically setup to allow you to fetch, pull, push to and from the remote repository, origin. But what is really going on? <strong>git remote</strong> is configured with a few lines of configuration in the <strong>config</strong> file inside the <strong>.git/</strong> directory.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s how it works:</p>
</div>
<div class="listingblock">
<div class="title">Create a new repository, called base, add a file to it, then commit.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mkdir base<span style="color: #990000">;</span>cd base<span style="color: #990000">;</span>git init
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/base<span style="color: #990000">/.</span>git<span style="color: #990000">/</span>
$ echo foo <span style="color: #990000">&gt;</span> bar<span style="color: #990000">.</span>txt
$ git add <span style="color: #990000">.</span>
$ git commit -m initial
<span style="color: #990000">[</span>master <span style="color: #990000">(</span>root-commit<span style="color: #990000">)</span> 548d762<span style="color: #990000">]</span> initial
 <span style="color: #993399">1</span> files changed<span style="color: #990000">,</span> <span style="color: #993399">1</span> insertions<span style="color: #990000">(+),</span> <span style="color: #993399">0</span> deletions<span style="color: #990000">(</span>-<span style="color: #990000">)</span>
 create mode <span style="color: #993399">100644</span> bar<span style="color: #990000">.</span>txt</tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Clone this repository, called klon.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cd <span style="color: #990000">..</span>
$ git clone base klon
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/klon<span style="color: #990000">/.</span>git<span style="color: #990000">/</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Initialize a new repository, called kopy.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mkdir kopy<span style="color: #990000">;</span>cd kopy<span style="color: #990000">;</span>git init
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/kopy<span style="color: #990000">/.</span>git<span style="color: #990000">/</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">The difference in configuration between the klon and the kopy.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ diff klon<span style="color: #990000">/.</span>git/config kopy<span style="color: #990000">/.</span>git/config
<span style="color: #993399">7</span><span style="color: #990000">,</span>12d6
<span style="color: #990000">&lt;</span> <span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
<span style="color: #990000">&lt;</span>       fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span>
<span style="color: #990000">&lt;</span>       url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
<span style="color: #990000">&lt;</span> <span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
<span style="color: #990000">&lt;</span>       remote <span style="color: #990000">=</span> origin
<span style="color: #990000">&lt;</span>       merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>To set up the newly created repository to work the same way the clone does, all I have to do is to edit this file to make it look the same. This is not what git does, so lets do it the git way.</p>
</div>
<div class="listingblock">
<div class="title">Fixing the remote configuration.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cd kopy
$ git remote add origin /Users/andersjanmyr/tmp/repos/base</tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">This adds the [remote "origin"] entry to the config file.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
        url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
        fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Fetching from the origin adds the remote heads to .git/.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git fetch
remote<span style="color: #990000">:</span> Counting objects<span style="color: #990000">:</span> <span style="color: #993399">3</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
remote<span style="color: #990000">:</span> Total <span style="color: #993399">3</span> <span style="color: #990000">(</span>delta <span style="color: #993399">0</span><span style="color: #990000">),</span> reused <span style="color: #993399">0</span> <span style="color: #990000">(</span>delta <span style="color: #993399">0</span><span style="color: #990000">)</span>
Unpacking objects<span style="color: #990000">:</span> <span style="color: #993399">100</span><span style="color: #990000">%</span> <span style="color: #990000">(</span><span style="color: #993399">3</span><span style="color: #990000">/</span><span style="color: #993399">3</span><span style="color: #990000">),</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
From /Users/andersjanmyr/tmp/repos/base
 <span style="color: #990000">*</span> <span style="color: #990000">[</span>new branch<span style="color: #990000">]</span>      master     -<span style="color: #990000">&gt;</span> origin/master
$ find <span style="color: #990000">.</span>git/refs
<span style="color: #990000">.</span>git/refs<span style="color: #990000">/</span>
<span style="color: #990000">.</span>git/refs/heads
<span style="color: #990000">.</span>git/refs/remotes
<span style="color: #990000">.</span>git/refs/remotes/origin
<span style="color: #990000">.</span>git/refs/remotes/origin/master
<span style="color: #990000">.</span>git/refs/tags</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now I can check out the <strong>origin/master</strong>, but if I do it the normal way, the configuration will not be set up correctly to allow me to pull and push the way i can with the clone.</p>
</div>
<div class="listingblock">
<div class="title">Checkout the master version with tracking information.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># DON'T DO THIS, It does not add the tracking information to the config file.</span></span>
$ git checkout -b master origin/master

<span style="font-style: italic"><span style="color: #9A1900"># This add the tracking information to the config file.</span></span>
$ git checkout --track -b master origin/master
Branch master <span style="font-weight: bold"><span style="color: #0000FF">set</span></span> up to track remote branch master from origin<span style="color: #990000">.</span>
Already on <span style="color: #FF0000">'master'</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">The following information is added to .git/config when --track is used.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
        remote <span style="color: #990000">=</span> origin
        merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>That&#8217;s it! Now the <strong>.git/config</strong> file looks the same as if I had done a normal clone, but lets continue. What do the entries in the config file mean.</p>
</div>
<div class="listingblock">
<div class="title">Definition of the remote.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
        url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
        fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Definition of the remote as git config commands.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git config remote<span style="color: #990000">.</span>origin<span style="color: #990000">.</span>url /Users/andersjanmyr/tmp/repos/base
$ git config remote<span style="color: #990000">.</span>fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="paragraph">
<p>The first part is just declaring the alias <strong>origin</strong> for the remote url (or local in this case <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
</div>
<div class="paragraph">
<p>The second part of the definition is more interesting. It sets up the <strong>refspec</strong> that will be used if you don&#8217;t provide anything on the command line. As we usually don&#8217;t provide a full refspec, most people don&#8217;t know what it is, this is extremely useful. In case you don&#8217;t know, the remote commands of git, <strong>push</strong>, <strong>pull</strong>, and <strong>fetch</strong> take a refspec as their last parameter. It is just that we usually just refer to a small part of it.</p>
</div>
<div class="listingblock">
<div class="title">Usage of the remote git commands.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>git pull <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span>
git fetch <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span>
git push <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span></tt></pre>
</div>
</div>
<div class="paragraph">
<p>The format of a <strong>refspec</strong> parameter is an optional <strong>plus +</strong>, followed by the source ref <strong>src</strong>, followed by a <strong>colon :</strong>, followed by the destination ref <strong>dest</strong>.</p>
</div>
<div class="paragraph">
<p>It defines what dest object should be updated by the src object.</p>
</div>
<div class="listingblock">
<div class="title">Example definition of refspec.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># The local</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># +&lt;src&gt;:&lt;dest&gt;</span></span>
<span style="color: #990000">+</span>refs/heads/spike<span style="color: #990000">:</span>refs/remotes/origin/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>In our day-to-day usage of git, we usually don&#8217;t use the full syntax of the refspec. Instead we just refer to simple names. Like this.</p>
</div>
<div class="listingblock">
<div class="title">Day-to-day usage of refspecs.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Push the local branch to the remote branch with the same name</span></span>
$ git push origin
<span style="font-style: italic"><span style="color: #9A1900"># Pull the master into the local master.</span></span>
$ git pull origin master
<span style="font-style: italic"><span style="color: #9A1900"># Fetch the master of the origin and put the result in the remote experimental</span></span>
$ git fetch origin master<span style="color: #990000">:</span>refs/remotes/origin/experimental</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The above really means:</p>
</div>
<div class="listingblock">
<div class="title">Definition of the branch, expanded</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Push the local branch to the remote branch with the same name</span></span>
$ git push refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span>
<span style="font-style: italic"><span style="color: #9A1900"># Pull the master into the local master.</span></span>
$ git pull origin refs/heads/master<span style="color: #990000">:</span>refs/remotes/origin/master
<span style="font-style: italic"><span style="color: #9A1900"># Fetch the master of the origin and put the result in the remote experimental</span></span>
$ git fetch origin refs/heads/master<span style="color: #990000">:</span>refs/remotes/origin/experimental</tt></pre>
</div>
</div>
<div class="paragraph">
<p>From the above syntax, it is also possible to decrypt the obscure syntax used when deleting a remote branch. Deleting is the same as pushing to a remote branch without giving a local branch.</p>
</div>
<div class="listingblock">
<div class="title">Delete a remote branch.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Delete the remote branch serverfix</span></span>
git push origin <span style="color: #990000">:</span>serverfix</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now, we are down to the last part of the configuration, the branch definition.</p>
</div>
<div class="listingblock">
<div class="title">Definition of the branch</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
        remote <span style="color: #990000">=</span> origin
        merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The first part <strong>branch.master.remote</strong>, tells git to use <strong>origin</strong> as the default remote, if none is given for this local branch.</p>
</div>
<div class="paragraph">
<p>The second part tells git which remote branch to use when merging. This also affects pull and fetch. Depending on your settings of <strong>push.default</strong>, it will also affect push.</p>
</div>
<div class="paragraph">
<p>Hopefully this has clarified some of the intricacies of git remoting. Just remember that if you make a mistake, you can always fire up an editor and edit the config file directly.</p>
</div>
<div class="paragraph">
<p>I&#8217;ll finish up with some more commands that can be used to get information about the remote.</p>
</div>
<div class="listingblock">
<div class="title">Additional remote commands, to explore a remote.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Show all remote branches</span></span>
$ git branch -r
  origin/cucumber
  origin/customercare-<span style="color: #993399">0.6</span><span style="color: #990000">.</span>x
  origin/master

<span style="font-style: italic"><span style="color: #9A1900"># Show all remotes verbosely</span></span>
$ git remote -v
origin  /Users/andersjanmyr/tmp/repos/base <span style="color: #990000">(</span>fetch<span style="color: #990000">)</span>
origin  /Users/andersjanmyr/tmp/repos/base <span style="color: #990000">(</span>push<span style="color: #990000">)</span>

<span style="font-style: italic"><span style="color: #9A1900"># Show info about the remote</span></span>
$ git remote show origin
<span style="color: #990000">*</span> remote origin
  Fetch URL<span style="color: #990000">:</span> /Users/andersjanmyr/tmp/repos/base
  Push  URL<span style="color: #990000">:</span> /Users/andersjanmyr/tmp/repos/base
  HEAD branch<span style="color: #990000">:</span> master
  Remote branches<span style="color: #990000">:</span>
    experimental stale <span style="color: #990000">(</span>use <span style="color: #FF0000">'git remote prune'</span> to remove<span style="color: #990000">)</span>
    master       tracked
  Local branch configured <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #FF0000">'git pull'</span><span style="color: #990000">:</span>
    master merges with remote master
  Local ref configured <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #FF0000">'git push'</span><span style="color: #990000">:</span>
    master pushes to master <span style="color: #990000">(</span>up to date<span style="color: #990000">)</span>

<span style="font-style: italic"><span style="color: #9A1900"># List the remote heads of the origin</span></span>
$ git ls-remote --heads origin
548d7624f5385d36314e8ab61e61e8872c0bfe90        refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>That&#8217;s it for today.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven automatic build versioning and Git against Subversion</title>
		<link>http://blog.jayway.com/2009/06/04/maven-automatic-build-versioning-and-git-against-subversion/</link>
		<comments>http://blog.jayway.com/2009/06/04/maven-automatic-build-versioning-and-git-against-subversion/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 14:36:13 +0000</pubDate>
		<dc:creator>Erik Ogenvik</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[version controlling]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=1869</guid>
		<description><![CDATA[If you use Git locally against a Subversion repository you might run into problems if your project is set up to generate automatic build numbers through the buildnumber-maven-plugin, since the plugin might be setup to get the build numbers from Subversion. Through some use of additional profiles you can work around this.]]></description>
			<content:encoded><![CDATA[<p>One of the nicest features of Git is that it's possible to use it locally against a Subversion server. For many this is a crucial selling point as it allows individual developers to take advantage of Git while not requiring that the entire project switches version control from Subversion. On your local Git repository you're then free to do as many branches as you like, or otherwise take advantage of the many nice features in Git.<span id="more-1869"></span></p>
<p>However, if your project is set up to use the Maven automatic build versioning as provided by the buildnumber-maven-plugin you will run into problems if it is set to get the build numbers from the Subversion revision number. Since your local checkout is against Git, and not Subversion, the build will fail since the Subversion commands won't work.<br />
One solution for this could be to alter the plugin configuration to get the build number from the date or something similar, but that's not always possible. You might have a build server setup that depends on the build number matching the revision number, and imposing such a change might break other functionality or processes.</p>
<p>Instead you can add an additional profile to the Maven POM which will only be triggered in the absence of a .svn directory (i.e. when not using Subversion). In this profile you can override the default configuration for the build number generator to instead use the date for build numbers. This means that your builds will have different build numbers from the integration builds, but at least it will compile on your git checkout.</p>
<p>The profile will look like this:</p>
<pre>&lt;profile&gt;
  &lt;!--
  This profile is here for triggering when another scm than svn is
  used (for example git). Instead of getting the version build number
  from svn we will use the build date and the user name.
  --&gt;
  &lt;id&gt;buildnumber-git&lt;/id&gt;
  &lt;activation&gt;
    &lt;file&gt;
      &lt;missing&gt;.svn&lt;/missing&gt;
    &lt;/file&gt;
  &lt;/activation&gt;
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;buildnumber-maven-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;create&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;doCheck&gt;false&lt;/doCheck&gt;
          &lt;doUpdate&gt;false&lt;/doUpdate&gt;
          &lt;format&gt;{0,date,yyyy-MM-dd_HH-mm}_{1}&lt;/format&gt;
          &lt;items&gt;
            &lt;item&gt;timestamp&lt;/item&gt;
            &lt;item&gt;${user.name}&lt;/item&gt;
          &lt;/items&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/profile&gt;</pre>
<p>This way Subversion and Git users can live happily together in the same project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/06/04/maven-automatic-build-versioning-and-git-against-subversion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

