Merge multiple Subversion repositories into a single Git repository
If you want to move your subversion repository to a git repository already exist tools make this porting in an easy way. But if you want to move and merge more than one subversion repositories into a single git repository you have mo make some manual steps.
At first please note subversion and git have different working method especially regarding tags and branches. This mean conversion will change and, in some case loose, some of the information you have into the subversion repository. Keep in mind this point before decide to make the porting.
Merge multiple svn repositories into a single svn repository
The trick is basically to create a single svn repository that include all your multiple svn repositories and than convert into git one. To make this action is necessary to dump the full history of each svn repositories. Subversion package (also if you installed TortoiseSVN) make available the tool svnadmin but if you work under Windows you can use my tool SVN Backup Tool to make this step more easily. In any case the use of the command line tool is very easy as follow:
svnadmin dump http://url_to_svn_1 > svn_1.dmp svnadmin dump http://url_to_svn_2 > svn_2.dmp svnadmin dump http://url_to_svn_3 > svn_3.dmp ....
This command will create the svn_x.dump by redirect all the output text of the dumping tool to the .dump file. Now you have to create a local subversion repository. Just type the following command or, if you use TortoiseSVN, just make a new folder, click right mouse button and select the option "Create repository here":
svnadmin create single-svn-repo
Now you must checkout this repository into a folder. This because you have to "prepare" this repository to include your multiple repositories to merge. Basically you have to make a new folder for each repository you want to merge in. This folder will be the root of imported repository. Following our example of three repositories to merge, after checkout we'll make the three folder, add these folders to the repository and commit as follow:
svn co file:///path/to/single-svn-repo single-svn-repo-folder cd single-svn-repo-folder mkdir folder_svn_1 mkdir folder_svn_2 mkdir folder_svn_3 svn add . --force svn ci -m "Base folders structure"
Again if you have TortoiseSVN you can make all these steps in visual mode, no need to type anything. Unfortunately last step of this phase have to be typed manually since, from what I know, TortoiseSVN doesn't have a command to make this action. Here you have to load and "associate" each single svn repository to merge to each folder just created as follow:
svnadmin load single-svn-repo --parent-dir folder_svn_1 < svn_1.dmp svnadmin load single-svn-repo --parent-dir folder_svn_2 < svn_2.dmp svnadmin load single-svn-repo --parent-dir folder_svn_3 < svn_3.dmp
Now you have the single svn repository with inside all sources and history of separate imported repositories. You can check the log to verify if all is ok. Here is also the occasion to make changes into commits info if necessary.
Migrate the just created Subversion repository to Git repository
Git tool already have instrument to make the porting from an svn repository but it require some additional info regarding the authors of each commit. Subversion save commits using username only but Git set additional info like email. To make the correct match you have to create a text file with a simple syntax to instruct Git regarding how to substitute svn username to git one. The file have to be filled in this way:
svn_username_1 = Name Surname <user1@xxxx.com> svn_username_2 = Name Surname <user2@xxxx.com>...
On the left side the list of svn usernames present in the commits inside svn repository to convert. On the right side the substitution to apply into the converted git repository. Name this file as you want, in this example we can name it svn_usernames.txt. Now make a new folder to contain git repository, enter into it and type the following command:
git svn init file:///path/to/single-svn-repo --no-metadata git config svn.authorsfile ../svn_usernames.txt git svn fetch
If all params are correct git should start to make the conversion. Based to the size of the svn repository to import the conversion will take some time. Once finished you'll have the git with imported subversion repositories. However, as already said, tags and branches work in different mode into git, this mean you lost these info as you was accustomed to "manage" using subversion. The typical svn structure composed by folders branches, tags and trunk is still maintained inside git repository but doesn't have much sense. Is possible to convert tags and branches to git style but require manual work or some script for speed up the job.
Comments
Post a Comment