For some reason (due to complicated conversion from SVN) I have two Git repositories:
- git repo A contains all history up to 31st December 2021
- git repo B contains all history from 1st January 2022 on
Now I would like to "merge" them in a way that I have the whole history, i.e. first the main branch of repo A and then the main branch from repo B.
I have not really understood yet how to do this properly.
- If I just merge the two repos, then I get a merge commit at the end, which is also pretty meaningless because I do not want to have the content of repo A merged into B, since B is more recent.
- If I rebase the main of B on the main of A I get kind of what I wanted but I am not sure whether the newly generated commits (from the ones of repo B) may have content I don't want, e.g. old files.
Can someone tell me how to do this properly?
Create a working repository.
Fetch the two branches into the repository.
Rebase BranchB onto BranchA, preserving BranchB's log graph.
The current BranchB contains the histories of BranchA and the old BranchB.
Suppose the head of BranchA is
Xand the root of BranchB isY. The abovegit rebasemight not work as expected. It could still mergeXandY. I don't know what your branches are like. If it does not work, here's another method that I'm sure can work.After fetching the 2 branches, first create an equivalent
Yon BranchA.Then rebase the commits after
Ytill the head of BranchB onto BranchA, preserving BranchB's original log graph.The 2nd method first creates a commit
Y'based onX. It does not mergeXandY. It has the same contents withY.git checkout Yandgit checkout Y'result in the same files.