Now I know most git experts will immediately think of git rebase
, but I am using the word \"rebase\" in the more general sense: I have the following structure o
Use a subtree merge.
I would list out the steps, but they are in the answer to this question: How do you merge two git repositories?
Quick and easy way:
Rename all files in src, so they will start with src/
. Add src repo as remote, fetch & merge. Drop old src repo, everything is now in ./
.
This will leave you with this action recorded in history.
History rewrite:
To make this merge invisible, you need to use git filter-branch --tree-filter
to add src/
prefix in src repository. Then add this as a remote to ./
repository and fetch it (no merge yet). To blend history nicely, you need to reorder commits. Use git log --date-order master src/master
to retrieve these commits in correct order and cherry-pick them:
git checkout -b new-master your-first-commit
git log --format='%H' --date-order --reverse master src/master | xargs git cherry-pick
This basically does merge sort on your commits and lines them up to linear history.
This is will not preserve your merges, so dont do it unless you have flat history. In that case use only filter-branch and then do normal merge.
No really use if this would work but could be worth a try. Assuming that the src is on a remote server and the parent is on a remote server. You can try the following.
I needed to do the same thing and this worked for me:
From the parent repo,
git remote add -f subrepo git@github.com:sub/repo.git
git merge -s ours --no-commit subrepo/master
git read-tree --prefix=subrepo/ -u subrepo/master
git commit -m "Subtree merged"
This is from a GitHub post that also has more detail: https://help.github.com/articles/about-git-subtree-merges/