title: error combining git repositories into subdirs
body: <p>I have looked at several threads addressing this. </p>
  
  <p><a href="https://stackoverflow.com/questions/277029/combining-multiple-git-repositories">Combining multiple git repositories</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3369591/combining-multiple-git-repositories-having-a-space-in-their-name">Combining multiple git repositories having a space in their name</a></p>
  
  <p>I also looked at the git filter-branch manpage.</p>
  
  <hr>
  
  <p>update</p>
  
  <p>I have changed to a 2 script system:</p>
  
  <pre><code>#!/bin/bash
  git filter-branch --index-filter '~/doit.sh' HEAD
  </code></pre>
  
  <p>and doit.sh</p>
  
  <pre><code>#!/bin/bash
  git ls-files -s | \ 
      sed "s-\t-&amp;data/perl_modules/-" | \ 
      GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info &amp;&amp; \
      mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
  </code></pre>
  
  <p>This avoids the previous error, but now gets this (replaced path with [...]):</p>
  
  <pre><code>Rewrite c35e4ef0626fb2045f57fa5b605e7663b8d06196 (1/10977)mv: cannot stat `[...]/.git-rewrite/t/../index.new': No such file or directory
  index filter failed: ~/doit.sh
  </code></pre>
  
  <p>When I run the </p>
  
  <pre><code>ls-files- s | sed ... | git update-index ...
  </code></pre>
  
  <p>I get the index file it should generate. As well when I change the doit.sh file to output the result of sed instead of piping it to git update-index it appears to produce the proper output... it seems git update-index is simply not creating the file when run under --index-filter....</p>
  
  <hr>
  
  <p>Update again:</p>
  
  <p>When I change</p>
  
  <p>mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"</p>
  
  <p>to </p>
  
  <p>mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true</p>
  
  <p>It fails the first mv, but all the others (so far) are working.</p>
  
  <hr>
  
  <p>All of this culminated in this script:</p>
  
  <pre><code>git filter-branch --index-filter \
      'git ls-files -s | sed "s-\t\"*-&amp;data/perl_modules/-" |
              GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                      git update-index --index-info &amp;&amp;
       mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
  </code></pre>
  
  <p>Theoretically this script should take all the files in the repository, shove them into data/perl_modules/, and rewrite history so that it appears the files have always been in that directory.</p>
  
  <p>However I get this error:</p>
  
  <pre><code>fatal: ambiguous argument 'ls-files': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions
  </code></pre>
  
  <p>Not sure how to proceed, I don't understand the script well enough to debug it, and it is taken directly from the git filter-branch manpage.</p>
  
  <p>I have tried this both before and after manually moving the files to the subdir in case it required they be moved, or required they not be moved.</p>