ms.xy.orgStuff goes here.
http://ms.xy.org/
Mon, 04 May 2015 15:56:18 +0000Mon, 04 May 2015 15:56:18 +0000Jekyll v2.5.3Squashing top commits<p>Sometimes you find yourself wanting to squash the top commits of a
branch down to just one commit. Most of the time this can be
accomplished with an interactive rebase:</p>
<pre><code>$ git log -n 3 --oneline
474142a Update link to Pro Git in CONTRIBUTING page
3a758a8 Update link to Pro Git in CONTRIBUTING page
b22ae59 update org name in links
$ git rebase -i b22ae59
</code></pre>
<p>Changing the keyword <code>pick</code> on the second line to <code>fixup,</code> or <code>f</code> for
short, will squash the two commits into one.</p>
<pre><code>pick 3a758a8 Update link to Pro Git in CONTRIBUTING page
fixup 474142a Update link to Pro Git in CONTRIBUTING page
</code></pre>
<p>This should result in something like:</p>
<pre><code>$ git log -n 2 --oneline
4c3d80a Update link to Pro Git in CONTRIBUTING page
b22ae59 update org name in links
</code></pre>
<p>Sometimes rebasing directly is not feasible, e.g. when you have a
botched merge commit that you have fixed, but later realized you
wanted to roll into the same commit. In this scenario you can usually
use a combination of <code>reset</code> and <code>commit --amend</code>. Using the same
example as above:</p>
<pre><code>$ git log -n 3 --oneline
474142a Update link to Pro Git in CONTRIBUTING page
3a758a8 Update link to Pro Git in CONTRIBUTING page
b22ae59 update org name in links
$ git reset --soft 3a758a8
$ git commit --amend -C HEAD
</code></pre>
<p><code>reset --soft</code> will rewind the current branch, but leave the index
intact so that <code>commit --amend</code> can update the first commit. Adding
<code>-C HEAD</code> will reuse its commit message. The end result should be similar:</p>
<pre><code>$ puter:spring-framework(master) ms$ git log -n 2 --oneline
46584d3 Update link to Pro Git in CONTRIBUTING page
b22ae59 update org name in links
</code></pre>
Tue, 04 Mar 2014 00:00:00 +0000http://ms.xy.org/2014/03/04/squashing-top-commits/
http://ms.xy.org/2014/03/04/squashing-top-commits/