I want to extend on another question I had: Merge two Git repositories and keep the master history
I have succeeded in merging 2 different repo\'s into one repo. I n
As you've discovered, rebase
isn't the command you want to use to stitch histories together (because it actually rewrites history). Early Git had a feature (hack) designed specifically for what you're trying to do: graft points. Even better, since 1.6.5 you can use git replace --graft instead:
git checkout master
git replace --graft $(git log RepoB/master --format=%H | tail -1) HEAD
git replace --graft $(git log RepoA/master --format=%H | tail -1) RepoB/master
git reset --hard RepoA/master
(git log RepoA/master --format=%H | tail -1
returns the initial commit from RepoA
)
Technically you could skip the first replace
if you don't actually have anything of value yet in master
, yielding just history with RepoB + RepoA.
These commands create entries in refs/replace/*
that can be pushed and pulled to share your revised history with others. Or, if you don't care about preserving the SHAs of RepoA/RepoB, you can make the replacements permanent by running git filter-branch --all
to produce a "real" set of commits of the desired lineage.