2

I have an SVN repo which looks like this:

  • Trunk:
    • dir_1
    • dir_2
    • dir_3
    • dir_4
    • dir_5
    • dir_6

and I wish to Migrate only directories dir_1,dir_2 and dir_5 to a new Git repository including all the branches, and history of those directorys. so that the outcome will be:

  • master:

    • dir_1
    • dir_2
    • dir_5

Is that possible?

3
  • Where do the branches live? Commented Mar 12, 2017 at 15:39
  • Is this about a one-time migration and you only use Git afterwards, or do you want to commit back to SVN from the Git clone? Commented Mar 14, 2017 at 14:40
  • this is a one-time migration and the intention is to use Git only after that migration.. Commented Mar 16, 2017 at 12:29

2 Answers 2

4

git-svn is not the right tool for one-time conversions of repositories or repository parts. 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.

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.

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 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. :-)

Sign up to request clarification or add additional context in comments.

6 Comments

Where's the syntax example for svn2git?
The repo of the tool provides usage examples. It also links to the KDE wiki describing the usage. And there is also a link to the KDE ruleset that serves as further examples.
The svn2git developer doesn't offer any compiled binaries, so if you're on other platforms (eg, Windows like me), get ready to compile it yourself.
That's right, but you can also simply use a Docker image that has it included, or use it from a WSL distribution on Windows, there are many ways, but the tool is worth it for getting a proper transformation :-)
All I can find is the source code. Where is a compiled release that works on WSL or the Docker image you reference? I found a nine-year-old Docker image (hub.docker.com/r/sawano/svn2git), and the source code you've linked to contains changes from this year. Not releasing installation packages or, at the very least, compiled binaries will dramatically limit the size of your user base.
That's the wrong svn2git as I detailed in my answer. I agree that missing binaries is bad, but it is not my project, I'm just a user and contributor. The svn-all-fast-export Docker image which should be the right tool is also 6 years old, but you can also just follow the readme that shows how to run the tool using the Dockerfile in the sources with Docker or Podman easily. On WSL you could just install the package from the repository, like svn-all-fast-export on Ubuntu.
2

You can use git-svn with the --include-paths option:

git svn clone <svn url> --trunk=Trunk --include-paths="dir_1\/|dir_2\/|dir_5\/" --no-metadata

The input to --include-paths is regex so make sure it does not match additional folders in the repository. Use the --no-metadata flag only if you will not commit to the svn repository again.

1 Comment

Doing this, however, will include the entire SVN commit history of Trunk in the git log. What if I only want the commit histories of dir_1, dir_2 and dir_5 in the git log?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.