Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use svn2git on repository

I'm using svn2git to test the migration of an svn repo to a git. Now my svn is build like thise

myproj contains

repo1 /
repo2 (obsolete)/
old/

Every repo contains its own branches, tags etc. I only need everything which is in repo1. When I start the process I get this:

svn2git https://server/myproj/repo1 --username LVO

output:

Initialized empty Git repository in /folder/.git/
Using higher level of URL: https://server/myproj/repo1 => https://server/myproj

And than the process starts. I'm afraid it's taking all the other old repo's too. Is this the right way to start it?:

$ svn2git https://server/myproj/repo1 --username xxx --trunk=/repo1 --branches=/repo1 --tags=/repo1 

(especially the trunk thing is not clear for me). How do I have to launch svn2git when my repo is in this tree.

like image 937
DenCowboy Avatar asked Aug 30 '25 16:08

DenCowboy


2 Answers

For a one-time migration git-svn is not the right tool for conversions of repositories or parts of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.

The svn2git tool you use is based on git-svn and thus suffers from most of the same drawbacks, only fixing some in the post-clone actions.

There are plenty tools called svn2git, the probably best one is the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.

You will be easily able to configure svn2gits rule file to produce the result you want from your current SVN layout, including any complex histories.

If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of an SVN repository when migrating it to Git.


Even though git-svn (or the svn2git that is based on it) is easier to start with, here are some further reasons why using the KDE svn2git instead of git-svn is superior, besides its flexibility:

  • the history is rebuilt much better and cleaner by svn2git (if the correct one is used), this is especially the case for more complex histories with branches and merges and so on
  • the tags are real tags and not branches in Git
  • with git-svn the tags contain an extra empty commit which also makes them not part of the branches, so a normal fetch will not get them until you give --tags to the command as by default only tags pointing to fetched branches are fetched also. With the proper svn2git tags are where they belong
  • if you changed layout in SVN you can easily configure this with svn2git, with git-svn you will loose history eventually
  • with svn2git you can also split one SVN repository into multiple Git repositories easily
  • or combine multiple SVN repositories in the same SVN root into one Git repository easily
  • the conversion is a gazillion times faster with the correct svn2git than with git-svn

You see, there are many reasons why git-svn is worse and the KDE svn2git is superior. :-)

like image 174
Vampire Avatar answered Sep 02 '25 05:09

Vampire


I've spent about a year of translation all of mine SVN projects to the Git and can tell now that there is no better tool other than... SubGit (is free for the SVN to Git one time translation)

https://subgit.com/documentation/howto.html

But, it is not the only thing you have to use on a way from the SVN into Git.

One thing you must understand is that there is no tools for truly automatic translation from the SVN into Git. And you will suffer if would not drop support of an SVN repository after the translation. The SVN is too different comparing to the Git, so the only decision here is to use Git instead of SVN completely.

The SubGit config must be correctly configured for the translation. The steps for the SubGit basically looks like this:

  1. subgit configure --layout auto SVN_PROJECT_URL repos.git
  2. Open and edit these files from the repos.git directory:
    • .git/subgit/config
    • .git/subgit/authors.txt
  3. subgit import repos.git

Because SubGit config file does not suggest all fields correctly and by default, then these fields are most important for edit:

  1. [svn] url = ...
  2. [svn] trunk = ... branches = ... tags = ... shelves = ...
  3. [svn] gitCommitMessage = ...
  4. [auth "default"] sshKeyFile = ... sshKeyFilePassphrase = ...
  5. [translate] externals = true

Examples:

  1. url = svn+ssh://[email protected]/p/project/repo
  2. trunk = trunk:refs/heads/master branches = branches/:refs/heads/ tags = tags/:refs/tags/ shelves = shelves/:refs/shelves/
  3. gitCommitMessage = %message\n\ngit-svn-id: svn+ssh://svn.code.sf.net/p/project/repo/%branch@%revision
  4. Required for the svn+ssh authentification. Ye, even if you read the public repository.
  5. Creates the .gitsvnextmodules text file in the root of the Git repository. Basically is used for the history, but can be used for the externals checkout. Ex: previous versions of the SmartGit tool: https://www.syntevo.com/smartgit/ (where the SVN support has existed)

Description:

  1. The url is used to pull the SVN repo.
  2. trunk, branches, tags, shelves is filters for mapping from SVN into Git. Basically the SubGit tries to autodetect the branches. Yes, you can use svneverever to introspect the SVN branches and changes over the time. But it is pointless, when you must write down a filter manually for the tools like svn2git. You will never write it absolutely correctly, especially for thousands revisions made by many persons. Better to drop it out and write down only those filters you absolutely need at the moment for the LAST revision and translate the rest of SVN repository without any special manual mapping. You just won't be used it in the Git so why bother?
  3. The gitCommitMessage is useful if you want to associate each commit in the Git with the commit from SVN. The <svn-repo-guid> is a placeholder for the GUID of the repo repository, you must put it the real GUID. The git-svn tool does the same.

The SVN externals can be replaced by the vcstool with the sparse checkout feature has implemented in the fork: https://github.com/plusone-robotics/vcstool (https://github.com/plusone-robotics/vcstool/pull/1). No need to use scripts for that like this: https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/convert-svnexternals

Another details about svn:externals replacement:

  • https://github.com/dirk-thomas/vcstool/issues/243
  • https://github.com/newren/git-filter-repo/issues/459
  • https://github.com/chronoxor/gil/issues/6

The rest of questions can be asked on the forum: https://support.tmatesoft.com/


Git modules experience : https://gist.github.com/andry81/b0000d2ddfa890f7ac68f1cabb6c1978

Related answers:

  • svn to git migration with nested svn:externals :
    svn to git migration with nested svn:externals
  • git-svn places .git folder in the same directory as the project parent folder instead of source folder :
    git-svn places .git folder in the same directory as the project parent folder instead of source folder
like image 38
Andry Avatar answered Sep 02 '25 06:09

Andry