While the answer @acran gave does solve the problem, it is also possible and sometimes advantageous to first convert the SVN repository to Git and to then split the big monorepo into multiple smaller repositories.
1. Converting SVN to Git
If your SVN repository has a standard layout (subdirectories branches
, tags
and trunk
) and you don't need any other bells and whistles, this is quite easy:
$ git svn clone <url_to_subversion_repo>
This command has two gotchas:
git svn
uses the SVN login as Git author name. It also uses some default mail address (<author_name>@localhost, I think, though I am not sure). If this is not what you want, you can use an authors file. Add a file user_mapping.txt
mapping SVN users to git users:
svn_user_1 = Git User 1 <user1@example.com>
svn_user_2 = Git User 2 <user2@example.com>
And then call git svn clone
with this file:
$ git svn clone --authors-file=user_mapping.txt <url_to_subversion_repo>
- As SVN tags can change,
git svn
imports them as Git branches. If you want, you can convert them.
git svn clone
checks out every revision of your SVN repo in order from the SVN server – if you have a big repository, this will take a while (my experience were multiple hours for ~50,000 revisions, I think, though I am not sure, this was years ago). If possible, you may want to run this command on the SVN server, espacially if you have a slow connection to it. Either way, go grab a cup of coffee (or five).
2. Splitting the Git repository
There are multiple tools to split up Git repositories into sub repositories. See for example this question. When I did this a few years ago, I used git filter-branch
, but this tool is now deprecated – you may still use it, or you may use git filer-repo
, though I don't have any experience with this tool.
The most upvoted answer to the question I linked uses git subtree filter
– I suggest not to use this answer, as git subtree filter
only converts one branch, in effect removing all other branches from your subrepositories.
Advantages
What are the advantages of this answer over converting every sub repository via git svn clone
?
- You only need to clone the SVN repository once. This is probably faster than cloning the sub folders for each project (though I have not tested this, it is only an educated guess).
- Cloning a SVN repository with the standard layout is better tested than cloning a SVN repository with a non-standard layout. In my experience,
git svn
does not always do what you want it to, so a more standard usage is probably more likely to result in what you want.
- If you want to rewrite the history of your new Git repositories (for example, to remove big binary files), you can rewrite the history of the monorepo between step one and step two. It would be a bigger effort to do this for every new sub repository.