0

I'm migrating code from SVN to GIT using SubGit. Some of my SVN repositories are built as:

SVN-Repo
    + Project1
        + trunk
        + branches
        + tags
    + Project2
        + trunk
        + branches
        + tags

Using SubGit:

subgit import --svn-url <svn_server>/SVN-Repo/Project1 C:\GitRepos\SVN-Repo\Project1.git --username xxx --password xxx.

After what I clone in a local repo.

Then:

git clone <Git_server>/_git/GIT-Repo
git push -u origin --all

The result is that in GIT-Repo at the end I don' have a folder named Project1 like I had with SVN. After investigation I dind't find the command allowing me to create this Proejct1 folder GIT repo.

Could you pelase help me?

Thank you in advance.

Didier
  • 11
  • What result do you want to achieve (I don't understand "git clone" + "git push" commands)? The commands you used created a Git repository at `C:\GitRepos\SVN-Repo\Project1.git` Isn't that what you want? You need not setup a Git server to serve Project1.git – Dmitry Pavlenko Apr 14 '16 at 12:30
  • I would like to have the same structure in GIT than in SVN. Meaning inside GIT repo: 2 sub-folders Project1 and Project2 with master... Because when I push Project1, then it's located at the root of the repo and not in a folder named Project1 – Didier Apr 14 '16 at 12:52
  • This is how Git works: a repository consists of branches, a branch has a tree (folder) that has it's own subtrees and so on. A branch cannot be contained inside a subtree. But there's a way to translate the whole your repository with 2 projects as a directory (not recommended) or to a repository with branches `refs/heads//*` or `refs/heads/-*` branchnames (this also doesn't make sense if the projects are not related). So what you did, was the most reasonable thing to do. – Dmitry Pavlenko Apr 14 '16 at 13:25

2 Answers2

1

There're 3 options

Option 1. What you already did (the most reasonable option). Convert both projects in SVN into 2 separate Git repositories. Then setup access to the repositories using GitLab, Atlassian Bitbucket Server, or any other Git server software.

Option 2. Treat the whole SVN repository as a single directory.

subgit configure --svn-url <svn_server>/SVN-Repo --layout directory C:\GitRepos\SVN-Repo\repo.git

subgit install C:\GitRepos\SVN-Repo\repo.git

Then you can run

subgit uninstall C:\GitRepos\SVN-Repo\repo.git

if you don't need continuous synchronization. In this case the Git repository will be rooted at SVN-Repo.

Option 3. One Git repository with branches from both projects.

subgit configure --svn-url <svn_server>/SVN-Repo C:\GitRepos\SVN-Repo\repo.git

Then edit repo.git/subgit/config to set

trunk = Project1/trunk:refs/heads/project1-master
branches = Project2/trunk:refs/heads/project2-master
branches = Project1/branches/*:refs/heads/project1-*
branches = Project2/branches/*:refs/heads/project2-*
shelves = shelves/*:refs/shelves/*
tags = Project1/tags/*:refs/tags/project1-*
tags = Project2/tags/*:refs/tags/project2-*

Then run

subgit install C:\GitRepos\SVN-Repo\repo.git

Then you can run

subgit uninstall C:\GitRepos\SVN-Repo\repo.git

if you don't need continuous synchronization.

In this case you have 1 Git repository with branches starting with project1- and project2- corresponding to your project. Instead of project1-/project2- you can also use project1//project2/.

So depeding on what you need you can choose one of these 3 options but the first one is the best one.

Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38
0

For a one-time conversion of SVN to git, I'd recommend using svn2git. There are many tools with this name. Probably the best is the KDE one at https://github.com/svn-all-fast-export/svn2git. To analyze the SVN repo history upfront for building up proper rules for svn2git, you might use svneverever from here: http://blog.hartwork.org/?p=763.

I transformed a couple of SVN repos to Git already with these and does a really great job.

And you can use the prefix rule there to get the subdirectory you want.

Vampire
  • 35,631
  • 4
  • 76
  • 102