Git squash commits in the middle of a branch
<p>I want to squash several commits together in the middle of a branch without modifying the commits before and after.</p>

<p>I have :</p>

<pre><code>A -- B -- C -- D -- E -- F -- G
|                             |
master                        dev
origin/master
</code></pre>

<p>I want to squash that into</p>

<pre><code>A -- H -- E -- F -- G
|                   |
master              dev
origin/master
</code></pre>

<p>Where <code>H</code> is equivalent to <code>B -- C -- D</code>. And I want to be able to specify the commit message of <code>H</code>. <code>A</code> is the last commit that has been pushed so all commits after that can be rewritten without messing up the server. The idea is to clean up the history before I fast forward <code>master</code>.</p>

<p>How can I do that ?</p>

<p>PS: Note that in my case I actually have a lot more than 3 commits to squash in the middle, but if I can do it with 3, I should be able to do it with more.</p>

<p>PPS: Also, if possible, I would prefer a solution where <code>E</code>, <code>F</code> and <code>G</code> remain untouched (mostly regarding the commit date).</p>