title: git filter-tree and modifying submodules
body: <p>I'm moving the contents of a git repository into another repository, and, for all of the regular commits, everything is fine. I have run into problems with submodules, though.</p>
  
  <p>Setting up, we start with two repos. We'll call them "docs" and "operations", and we want to move the contents of "docs" into a subdirectory of "operations", like this:</p>
  
  <pre><code>docs/
    file1.txt
    dir1/
      file2.txt
    other-docs/  &lt;- This is a git submodule
  
  operations/
    bin/
      do-things
    docs/
      important.txt
  </code></pre>
  
  <p>And we want the final version to look like this, where the "docs" repo ends up under "docs/legacy" in the operations repo:</p>
  
  <pre><code>operations/
    bin/
      do-things
    docs/
      important.txt
      legacy/
        file1.txt
        dir1/
          file2.txt
        other-docs/  &lt;- This is a git submodule
  </code></pre>
  
  <p>I've got a script that uses a combination of <code>git filter-branch --tree-filter</code> and <code>git rebase</code> (to rebase the new content onto the existing content and handle conflicts like <code>.gitignore</code> files) to perform the actual migration, but, after running the migration, I end up with:</p>
  
  <pre><code>operations/
    bin/
      do-things
    docs/
      important.txt
      legacy/
        file1.txt
        dir1/
          file2.txt
    other-docs/  &lt;- This is a git submodule
  </code></pre>
  
  <p>Where the <code>other-docs</code> submodule is still at the root of the new repo.</p>
  
  <p>I understand why this is happening. As I go through the commits to move things, there isn't an actual file for the submodule, so, in the "everything in this directory is committed exactly as you leave it" model of <code>git filter-branch --tree-filter</code>, there is <em>nothing</em> to "leave" for a submodule.</p>
  
  <p>So, first question: is there some aspect of using <code>git filter-branch</code> where I can account for this? One place I was wondering is if I can add <code>--commit-filter</code> and mess with things there, but I'm not completely clear on what the invariants around a commit filter are.</p>
  
  <p>If not there, is there somewhere else I can do this. As far as I can tell, I will have to modify the existing commits for submodules, basically "removing" the submodule in the old, incorrect location and "add" the submodule in the new, correct location. I suppose I could script through an interactive rebase operation, finding those commits and amending them. It just sounds like a lot of work if there is a better way.</p>
  
  <p>Any ideas appreciated.</p>