问题
I am looking to migrate my codebase from svn to git. There are too many branches in my svn repo. I only wish to clone couple of branches and merge them together and push it to git. I want to avoid cloning all branches as it takes long time. How do I achieve this?
After it's done, I want to periodically get update from those svn branches, merge them and update the git repo and the svn will be active for certain period of time. It would be waste of time if I have to clone it again. Is there a way to do what I require?
回答1:
I think SubGit tool might be the best solution for your case:
https://subgit.com
It allows translating data from SVN to Git including and excluding any branches/tags or even directories inside, so it's easy to get only those branches you want to have in Git. Say, if you have branches 'branch_1'… 'branch_N', but intend to have in Git only 'branch_3' and 'branch_4' (along with 'trunk'), then you can set SubGit as follows:
[svn]
trunk=trunk:/refs/heads/master
branches=branches/branch_3:/refs/heads/branch_3
branches=branches/branch_4:/refs/heads/branch_4
and only those branches will appear in Git.
SubGit supports continuous two-way mirror between SVN and Git, so it's perfectly possible not only get updates from SVN, but send those from Git, too. It also possible to only get updates from SVN by running import periodically, yet in this case, branches that came from SVN should not be changed in GIt.
回答2:
git svn fetch
(and clone
) have --ignore-paths and --include-paths so you can ignore some branches/tags (which are paths in SVN repo) or include only matching branches/tags. So it should be something like
git init from_svn
cd from_svn
git config svn-remote.svn.url "svn://…"
git config svn-remote.svn.include-paths "^/branches/3\." # Include only branches that match name 3.*
git svn fetch svn
来源:https://stackoverflow.com/questions/50746949/git-svn-clone-specific-branches-and-merge