title: git rebase interactive: squash merge commits together
body: <p>I wanted to have a simple solution to squash two merge commits together during an interactive rebase.</p>
  
  <p>My repository looks like:</p>
  
  <pre><code>   X --- Y --------- M1 -------- M2 (my-feature)
    /                 /           /
   /                 /           /
  a --- b --- c --- d --- e --- f (stable)
  </code></pre>
  
  <p>That is, I have a <code>my-feature</code> branch that has been merged twice recently, with no real commits in between. I don't just want to rebase the <code>my-feature</code> branch since it is a published branch of its own, I just want to squash together the last two merge commits into one (haven't published those commits yet)</p>
  
  <pre><code>   X --- Y ---- M (my-feature)
    /            /
   /            /
  a --- ... -- f (stable)
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>git rebase -p -i M1^
  </code></pre>
  
  <p>But I got:</p>
  
  <pre><code>Refusing to squash a merge: M2
  </code></pre>
  
  <p>What I finally did is:</p>
  
  <pre><code>git checkout my-feature
  git reset --soft HEAD^  # remove the last commit (M2) but keep the changes in the index
  git commit -m toto      # redo the commit M2, this time it is not a merge commit
  git rebase -p -i M1^    # do the rebase and squash the last commit
  git diff M2 HEAD        # test the commits are the same
  </code></pre>
  
  <p>Now, the new merge commit is not considered a merge commit anymore (it only kept the first parent). So:</p>
  
  <pre><code>git reset --soft HEAD^               # get ready to modify the commit
  git stash                            # put away the index
  git merge -s ours --no-commit stable # regenerate merge information (the second parent)
  git stash apply                      # get the index back with the real merge in it
  git commit -a                        # commit your merge
  git diff M2 HEAD                     # test that you have the same commit again
  </code></pre>
  
  <p>But this can get complicated if I have many commits, do you have a better solution ?
  Thanks.</p>
  
  <p>Mildred</p>