title: How to remove previously added git subtree and its history
body: <p>Many moons ago I added a subtree to my <code>git</code> repository. This subtree included several folders and files. I added the subtree instead of creating a submodule (as recommended). Now I realize I only want one of the files in the subtree and none of the rest. Even worse, when others <code>clone</code> my repository, what they get is not what is expected—there is some conflict with the subtree and the other code that I've created.</p>
  
  <p>I can get ride of the files/folders with </p>
  
  <pre><code>git rm subtree–folder1 subtree_folder2 subtree_files.*
  </code></pre>
  
  <p>however, I'm still left with a lengthy commit history from the subtree. </p>
  
  <p>I've done a fair amount of development since I originally added the subtree and can't lose the commit history that I've generated.</p>
  
  <p>In short this is what I would like:</p>
  
  <ol>
  <li>Remove all the subtree files/folders.</li>
  <li>Forget the history of all the subtree commits.</li>
  <li>Left with only my code and my history.</li>
  </ol>
  
  <p>Is this possible?</p>
  
  <p>PS. One possible complication is that I moved the single header file I wanted to keep from the subtree to some folder in my code. I hope this is not what is keeping me from forgetting the subtree history. </p>
  
  <h1>An Attempt</h1>
  
  <p>After a fresh checkout from the remote server I have the following:</p>
  
  <pre><code>$ ls
  .git             CMakeLists.txt   Read.cpp         logging.conf
  .gitignore       ENDF6            TestData         src
  .sparse-checkout LICENCE          doc              test
  .travis.yml      README.md        include          tools
  </code></pre>
  
  <p>Where <code>.gitignore</code> only has:
      build/
      debug/</p>
  
  <p>When I try the command as suggested I don't get a very happy response:</p>
  
  <pre><code>$ git filter-branch --index-filter 'git rm --cached -rf test tools src doc LICENCE README.md .travis.yml' HEAD
  Rewrite 2fec85e41e40ae18efd1b130f55b14166a422c7f (1/1701)fatal: pathspec 'test' did not match any files
  index filter failed: git rm --cached -rf test tools src doc LICENCE README.md .travis.yml
  </code></pre>
  
  <p>I'm not sure why it says it has a problem with <code>test</code> when it is clearly there. I'm baffled.</p>