Search code examples
gitsvngit-svn

Is one off svn to git migration without prefix safe?


I have a number of repositories in subversion that I want to migrate to git. Once the migration is complete, the svn repos will be marked read only and never committed to again. In the specific case I'm working on, there are two active branches, let's call them BranchA and BranchB. Once the migration is done, I would prefer to have them look like "regular" git branches without a prefix.

Currently I'm using the command:

 git svn clone --prefix=svn/ --stdlayout http://repos-url/ <git-name>

In which case my branches ends up being called svn/BranchA and svn/BranchB

But I would rather use

 git svn clone --prefix="" --stdlayout http://repos-url/ <git-name>

And have them being called BranchA and BranchB in git.

However, the docs warn against this saying

Setting a prefix (with a trailing slash) is strongly encouraged in any case...

But I'm not sure I understand why. It also says that the SVN url will be added as a "remote", but that's not really what I want.

I'm worried that by using --prefix="" I will run into some trouble at a later point, because I don't really understand the warning.

So I guess my questions are:

  • What are the downsides to using --prefix="" ?
  • Can I prevent svn-git from keeping a reference to the SVN repos?

Solution

  • You can simply not use --prefix at all. From the docs...

    --prefix=<prefix>

    This allows one to specify a prefix which is prepended to the names of remotes if trunk/branches/tags are specified. The prefix does not automatically include a trailing slash, so be sure you include one in the argument if that is what you want.

    If you don't want to prefix your branch names, don't use --prefix. This is primarily useful when you're mirroring an SVN repository to keep the SVN branches separate from your Git branches. If you're migrating you don't need that.

    The trailing slash note is just making it clear that if you say --prefix=foo you'll get fooBranchA and fooBranchB. It doesn't matter to Git if your branch name has a slash in it or not.

    It also says that the SVN url will be added as a "remote", but that's not really what I want.

    This is also used for mirroring, it's not useful when migrating.

    You can simply remove it later with git remote rm. Or you can ignore it. Remotes are attached to the physical .git directory sitting on your disk, they're not shared. This remote won't be pushed to a Git server. Anyone cloning the repository won't have this svn remote.

    So you can get a "clean" repository after migrating by simply cloning the migrated on. And you can clone directories.

    git clone path/to/migrated/repo path/to/clean/repo
    

    Bitbucket has a nice guide on migrating from SVN to Git.


    Unlike in SVN where "branches" are rather ponderous things, Git "branches" are just labels on the actual branches. And unlike SVN where history is like a stack of pancakes that you can only add to the top of, Git history is a graph of nodes and connections and can be changed.

    Rather than worrying about getting it just right in the migration, you can make little tweaks afterwards. For example, you can safely change the branch name in Git after the migration. And you can remove the SVN remote.