Reputation: 1871
I have a badly structured SVN repo. Let me try to give you an image.
svn-repo
|
|--branches
| |
| |-- project1
| |-- project2
| |-- tragetProject
| |
| |-- targetProject5.0.0
| |-- targetProject5.0.1
| |-- targetProject5.0.2
| |-- ...
|
|--trunk
|
|-- project1
|-- project2
|-- ...
The project I want to migrate is the "targetProject". Each branch is derived from the latest branch, eg. 5.0.1 is a branch from 5.0.0. So each branch in svn has the commit history of it's ancestor.
This is the process I tried in order to migrate to git.
git svn init [trargetProject5.0.2 Url]
git svn fetch
My issue is that although the svn branch has all commit history, after fetch, in git local master there is only the commit history of this branch and not of it's ancestors.
I need to get all history. I tried changing the git branch url in git config in order to fetch the commits for each branch but this also failed as "git svn rebase" did not work as expected. I also need to get new commits of a maybe new branch created in svn repo. Can anybody help or provide me a new way to deal with this? Thanks.
Upvotes: 1
Views: 2320
Reputation: 1871
Ok I have found the solution.
Instead of cloning the trunk of my huge repo I wanted to clone a certain branch. So using this command does the trick.
git svn clone -T branches/tragetProject/tragetProject5.0.2 http://example.com/PROJECT
This will clone the current branch and also search each parent for all commit history.
Because my svn repo is huge and all branches are linked together this command would take ages to complete and would fetch unwanted commits from legacy branches. By adding -r<revision>:HEAD
at the end you limit the clone investigation to certain revision.
So the the command becomes:
git svn clone -T branches/tragetProject/tragetProject5.0.2 http://example.com/PROJECT -r40000:HEAD
Hope this helps someone in the future.
ref https://gist.github.com/trodrigues/1023167#file-gistfile1-txt-L30
Upvotes: 2
Reputation: 38106
To migrate SVN to Git while keeping all the histories, you can use the command:
git svn clone <svn-repo URL> --branches=branches --tags=tags --trunk=trunk
Now all the commit histories are kept in git repo. By default, there only has the local branch master
, but you can find other branches by git branch -r
.
And the output of git branch -r
command looks like origin/branch1
. Then what you just need to do is checkout all the branches locally by git branch -b <local Branch name> <remote branchname>
.
As the example above, to checkout branch1
locally, you can use the command git checkout -b branch1 origin/branch1
.
Upvotes: 1