We have two Subversion repositories, each with a single project. So:
svn://server/svn/project_a
svn://server/svn/project_b
They are separate projects, and are in separate repositories with completely separate commit histories. Project A has r1, r2, ... r100
and Project B has r1, r2, ... r400
We would ultimately like to merge these two SVN repositories into a single Git repository. Whether the merge can take place in Git, or should take place in a third temporary SVN repository first, we ultimately want to see:
git://server/svn/projects/
Which is a repository with both Project A and Project B. They will be stored in separate folders, like:
git://server/svn/projects/project_a
git://server/svn/projects/project_b
So there won't be any conflicts "merging" the two. We were able to use this answer flawlessly to transfer a single SVN project into a single Git project, with commit history included.
We would like to merge our two SVN Projects A and B into a single Git repository, but we want the commits to be merged by date. ie:
8b8dad: Project A, r1 (first commit in Git)
dbdffe: Project B, r1 (child of previous)
0ae7f7: Project B, r2 ...
615b51: Project A, r2 ...
916e59: Project A, r3 ...
85f241: Project B, r3 ...
Is this possible? Should we merge the two SVN repositories into one, then import into Git? Or is it easier to leave them separate, and perform the merge during the Git import?
You can merge repository A into a subdirectory of a project B using the subtree merge strategy. This is described in Subtree Merging and You by Markus Prinz. (Option --allow-unrelated-histories is needed for Git >= 2.9.
Convert the SVN repository to a local Git repository. Synchronize the local Git repository when the SVN repository changes. Share the Git repository with your developers via Bitbucket. Migrate your development efforts from SVN to Git.
So I tried Craig's method, but this left me with a somewhat unsatisfactory history on the combined repository in the end. I found that checkout out all the svn repos into separate git ones and then branching them together made a nice history where three branches meet.
So first you do the "authors" step to create authors.txt:
someguy = Some Guy <[email protected]>
...
(no author) = no_author <no_author@no_author>
Now you have to check out all svn repos using git:
mkdir proja projb projc ...
Now you have to repeat the following for every project, and since your repos are probably not one single folder do an additional commit:
cd proja
git svn init https://svn.mycompany.com/svn/proja --no-metadata
git config svn.authorsfile ../authors.txt
git svn fetch
#here comes the additional part:
mkdir -p proja #proja/proja
git mv -k * proja #move everything in there
git commit -m "subtree proja"
Then I went and made my new combined repo in which i used a different branch for each subproject:
mkdir ../superproj
cd ../supeproj
git init
git commit --allow-empty #so that we have a master branch
git branch proja projb projc...
The following needs to be repeated for every sub-project:
git checkout proja
git remote add proja_rm ../proja
git pull proja_rm #probably add a branch (e.g. master)
git remote rm proja_rm #cleanup
Finally you can combine the whole thing into your master
git checkout master
git merge proja projb projc... #it all comes together
git push whereeveryouwant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With