I've been trying to decipher the git-filter-branch
command used here to rewrite the index such that all the repo contents are within a new directory, which is then used to move this to the subdirectory of another repo. Focussing on the specific command:
git filter-branch --index-filter '
git ls-files -s |
sed "s,\t,&'"$dir"'/," |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
' HEAD
This essentially seems to change the index to look from /folder1/path/to/file
to 'newrootfolder'/folder1/path/to/file
.
Questions:
- Where is the
GIT_INDEX_FILE
variable coming from, what is it set to and how does that entire line work? - How does the new folder(say
newrootfolder
) get automatically created in the repository - does git internally detect and create the directory?