I have looked at several threads addressing this.
Combining multiple git repositories
Combining multiple git repositories having a space in their name
I also looked at the git filter-branch manpage.
update
I have changed to a 2 script system:
#!/bin/bash
git filter-branch --index-filter '~/doit.sh' HEAD
and doit.sh
#!/bin/bash
git ls-files -s |
sed "s--&data/perl_modules/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
This avoids the previous error, but now gets this (replaced path with [...]):
Rewrite c35e4ef0626fb2045f57fa5b605e7663b8d06196 (1/10977)mv: cannot stat `[...]/.git-rewrite/t/../index.new': No such file or directory
index filter failed: ~/doit.sh
When I run the
ls-files- s | sed ... | git update-index ...
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....
Update again:
When I change
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
to
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true
It fails the first mv, but all the others (so far) are working.
All of this culminated in this script:
git filter-branch --index-filter
'git ls-files -s | sed "s-"*-&data/perl_modules/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new
git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
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.
However I get this error:
fatal: ambiguous argument 'ls-files': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
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.
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.
See Question&Answers more detail:
os