git within git - benclifford/text GitHub Wiki
(see also / merge single-repo-vs-many-modules)
a few ways:
- submodules submodule-like things (eg stack commits)
ugh
- subtrees
preserves actual commits so graph operations still work. git log doesn't work so well on directories because it can't follow the move that happened.
- filter-branch history rewriting
new commit ids, so can't do merges or other graph operations with an un-rewritten tree. so if you have outstanding dev branches that are un-merged these will need to be rewritten too - you can't keep some on your dev machine and play catchup later. (although you could cherry pick commits, perhaps)
-
get top repo in X/
-
get what-will-be-child repo in Y/
-
move everything in Y into a subdir in all of history credit
-
git checkout -b work
git filter-branch --index-filter ' git ls-files -s | sed "s-\t"*-&newproj/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE ' HEAD
that Y repo now looks like: Y/newproj/stuff...
-
now merge that into X:
-
cd X/
-
git remote add childrepo ../Y
-
git fetch childrepo
-
git merge childrepo/work --allow-unrelated-histories
done.