<?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>gitguru &#187; rebase</title>
	<atom:link href="http://gitguru.com/tag/rebase/feed/" rel="self" type="application/rss+xml" />
	<link>http://gitguru.com</link>
	<description>meditations on scm using git</description>
	<lastBuildDate>Wed, 25 Mar 2009 04:32:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rebase v Merge in Git</title>
		<link>http://gitguru.com/2009/02/03/rebase-v-merge-in-git/</link>
		<comments>http://gitguru.com/2009/02/03/rebase-v-merge-in-git/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 20:04:56 +0000</pubDate>
		<dc:creator>long</dc:creator>
				<category><![CDATA[commands]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[rebase]]></category>

		<guid isPermaLink="false">http://gitguru.com/?p=22</guid>
		<description><![CDATA[If you haven&#8217;t worked with a version control tool that allows for easy branching, you&#8217;re probably wondering what the difference is between rebase and merge and why you&#8217;d choose one over the other.
From the standpoint of the end result, a merge and a rebase in Git appear to do the same thing:
A + B + [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t worked with a version control tool that allows for easy branching, you&#8217;re probably wondering what the difference is between rebase and merge and why you&#8217;d choose one over the other.</p>
<p>From the standpoint of the end result, a <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html">merge</a> and a <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html">rebase</a> in Git appear to do the same thing:</p>
<p style="padding-left: 30px;"><strong>A</strong> + <strong>B</strong> + <strong>A&#8217;</strong> (merge) = <strong>A</strong> + <strong>A&#8217;</strong> + <strong>B</strong> (rebase)</p>
<p>Wouldn&#8217;t it be simpler to just choose one operation and stick with it?</p>
<p>The answer of course is no.  Otherwise you wouldn&#8217;t have the option.  (If you feel completely contrary, best of luck.  And choose merge.)</p>
<p>It really only becomes apparent once your development effort becomes hierarchical, either in terms of application lifecycle (such as dev, test and release versions) or in a team structure.  You&#8217;re now dealing with multiple branches, each with non-trivial changes that can and will occur independently.</p>
<p>Rebases are how changes should pass from the top of hierarchy downwards and merges are how they flow back upwards.</p>
<p>Let&#8217;s take a look in more detail at what is actually taking place in each operation for a parent branch <strong>A</strong> and a child branch <strong>B</strong>:</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Merge</span><strong></strong></p>
<p style="padding-left: 30px;"><strong>A</strong> + <strong>B</strong> + <strong>A&#8217;</strong> + <strong>dA&#8217;B</strong></p>
<p style="padding-left: 30px;">where <strong>A&#8217;</strong> are the changes being merged in and <strong>dA&#8217;B</strong> the resolution of merge conflicts from <strong>A&#8217;</strong> and the set of commits <strong>B</strong> on the current branch</p>
<p style="padding-left: 30px;">The changes introduced by <strong>A&#8217;</strong> and <strong>dA&#8217;B</strong> are grouped together into one merge commit <strong>A&#8221;</strong> = <strong>A&#8217;</strong> + <strong>dA&#8217;B</strong> that is added on top of the existing set of commits (<strong>A</strong> + <strong>B</strong>) and becomes the head of the current branch:</p>
<p style="padding-left: 30px;"><strong>A</strong> + <strong>B</strong> + <strong>A&#8221;</strong></p>
<p style="padding-left: 30px;"><strong></strong><span style="text-decoration: underline;">Rebase</span></p>
<p style="padding-left: 30px;"><strong>A</strong> + <strong>A&#8217;</strong> + <strong>B</strong> + <strong>dA&#8217;B</strong></p>
<p style="padding-left: 30px;">The rebase resets the starting point the branch and reapplies the set of commits <strong>B</strong>.  Merge conflicts <strong>dA&#8217;B</strong> are combined with these commits so they become grouped together <strong>B&#8217;</strong> = <strong>B</strong> + <strong>dA&#8217;B</strong>:</p>
<p style="padding-left: 30px;"><strong>A</strong> + <strong>A&#8217;</strong> + <strong>B&#8217;</strong></p>
<p>If you stare at it, you&#8217;ll realize that the rebase guarantees that the changes being brought it in from the other branch come in exactly as-is: <strong>A</strong> + <strong>A&#8217;</strong>.  Any conflicts are resolved and contained with the associated commits <strong>B&#8217;</strong> on the current branch.</p>
<p>Using merge to pull in changes from the higher-level branch mixes those changes with the resolved merge conflicts.  This means that the current branch won&#8217;t necessarily have the same state as the one it was based on (from the hierarchical structure).  And since the resolved conflicts are grouped all together in one merge commit, you&#8217;ve also made it harder to cleanly cherry-pick individual changes.</p>
<p>Having development lifecycle tracks and each local developer branch start from known consistent states is critical to reducing and resolving code issues.  Where a change occurs (or suddenly becomes missing) and who is responsible become easier to determine.  By using the rebase to pull in changes, you have that.</p>
<p>When you&#8217;re submitting changes back up the chain, you only want to add your changes on top of the existing commits of the higher-level branch.  Merge is clearly the operation for that.</p>
<p>Even if you&#8217;re a single developer with only a few branches, it&#8217;s worth it to get in the habit of using rebase and merge properly.  The basic work pattern will look like:</p>
<ol>
<li>Create new branch <strong>B</strong> from existing branch <strong>A</strong></li>
<li>Add/commit changes on branch <strong>B</strong></li>
<li>Rebase updates from branch <strong>A</strong></li>
<li>Merge changes from branch <strong>B</strong> onto branch <strong>A</strong></li>
</ol>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://gitguru.com/2009/02/03/rebase-v-merge-in-git/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
