title: Removing Git commits on a branch
body: <p>How do I remove commits that are branched off <code>master</code>?</p>
  
  <p>I have added a large library, along with a very rich commit history (and that predates my code) to a subdirectory via <a href="https://github.com/apenwarr/git-subtree" rel="nofollow" title="Git subtree">Git subtree</a>. I'd like to retroactively squash that entire history, <em>but still be able to merge in new commits to the library</em>.</p>
  
  <p>I have tried various combinations of <code>git rebase</code> but I never get the expected result [*].</p>
  
  <p>My repository looks something like:</p>
  
  <pre><code>A---B-----------F---G master
                 /
    ... C---D---E
  </code></pre>
  
  <p>and I'd like for it to look something like:</p>
  
  <pre><code>A---B-----------F'--G' master
                 /
                E'
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>A---B-------E'--F'--G' master
  </code></pre>
  
  <p>[*]:</p>
  
  <ul>
  <li><code>git rebase --onto C E master</code></li>
  <li><code>git checkout F; git rebase --onto C E master</code></li>
  </ul>