I know about git-svn and have used it to migrate SVN repositories into Git.
With one repo I have a specific requirement, which I can't find a solution for. That SVN repo contains multiple actual projects as subdirectories:
trunk/
project1/
project2/
project3/
branches/
branch1/
project1/
project3/
project2/
...
and so on...
What I want to do is import each of these "sub-projects" in its own repo in git - obviously, keeping revision history, branches, commit messages, tags, etc.
I can use --ignore-paths and --include-paths switches to only pull one of these sub-projects at a time, but they will still appear under the respective project1, etc. subdirectories. What I really want to end up with is the content of project being in the root in each branch (including trunk).
Is there a way to do this?
I found the solution. It's not as simple as git svn clone, but not too difficult. So, here's what I did (say, for project1 in the scenario from the question):
project1
git clone [email protected]:group/project1.git
cd project1
git svn init --stdlayout --no-metadata https://svn.server.com/group
Now, here's where the magic comes. If at this point I run git config --local --list, I get the following (only relevant lines shown):
svn-remote.svn.fetch=trunk:refs/remotes/trunk
svn-remote.svn.branches=branches/*:refs/remotes/branches/*
svn-remote.svn.tags=tags/*:refs/remotes/tags/*
All that I need to do now is git config --local --edit and add project1 in the correct places:
svn-remote.svn.fetch=trunk/project1:refs/remotes/trunk
svn-remote.svn.branches=branches/*/project1:refs/remotes/branches/*
svn-remote.svn.tags=tags/*/project1:refs/remotes/tags/*
Now you can git svn fetch
Set branches and tags:
for branch in `git branch -r | grep "branches/" | sed 's/ branches\///'`; do
git branch $branch refs/remotes/branches/$branch
done
for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do
git tag -a -m"Converting SVN tags" $tag refs/remotes/tags/$tag
done
And finally push it all to the remote:
git push --all origin
git push --tags origin
Now if you clone your repo, you'll get the content of project1 in the root of your cloned repo - exactly what I was looking for.
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