Migrate a repo not always using the trunk/branches/tags structure from SVN to GIT

I’m looking for a way to permanently (i.e. no gitsvn will be used after the import and the repo will be cloned again to get rid of all git-svn remainders) migrate one of my SVN repositories to git. Usually this would be an easy thing – just doing the steps explained at http://www.jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/.

However, in the SVN repository I switched to the trunk/branches/tags structure after some time, so about half of the ~2000 commits are working with the actual trunk being in / while the other half have it in /trunk/ (i.e. there’s one big commit moving everything) so neither using -s nor not using it when performing the git svn initialization will work properly.

  • git tfs branch --init --all errors
  • git branch --merged using plumbing commands
  • Visual Studio 2015 database(.mdf) versioning
  • Adding plugins from specific revision Github project to the Cordova project
  • How to set --work-tree or --git-dir in smartgit?
  • Git: Merge Multiple Branches
  • I’m now looking for a way to import the repository to git properly, i.e. preserving the branch information (no tags, I never created any) while not messing up old commits. In case that’s not possible I’d like to know if there’s a way to rewrite the old commits to change the repo so it uses the trunk/branches/tags structure – then I could simply use -s in git-svn.

  • Remove a file with a strange name from git
  • How to get Jenkins to connect to git repository
  • What does GIT PUSH do exactly?
  • Why does git keep deleting my folder?
  • folder structure in a mercurial repo?
  • git delete and recreate branch
  • One Solution collect form web for “Migrate a repo not always using the trunk/branches/tags structure from SVN to GIT”

    TL,DR: It is possible to fix a messy up repository like the one described in the question when some manual work is acceptable. The easiest way is doing it with the SVN dump file and then simply importing it using git-svn with the stdlayout option.

    I managed to do it by rewriting the svndump of the repository to include the proper structure from the beginning:

    svnadmin dump orig/ --incremental > repo.svndump

    Then I used a small inline Perl script to change the folders:

    perl -pe 's/^Node-path: (?!trunk|branches|tags)(.+)$/Node-path: trunk\/$1/g' repo.svndump > repo2.svndump

    Since the dump was now invalid – the trunk folder needed to be created in r0 and the commit moving everything from / to /trunk needed to be obliterated – I edited the dump file manually (luckily all metadata are plaintext) and added the following at the beginning of the changes for r0:

    Node-path: trunk
    Node-kind: dir
    Node-action: add
    Prop-content-length: 10
    Content-length: 10

    In the commit moving all the files I removed all actions and added the following to create the branches folder (likewise for the tags folder if I had used it)

    Node-path: branches
    Node-kind: dir
    Node-action: add
    Prop-content-length: 10
    Content-length: 10

    The edited dumpfile could now be loaded using svnadmin load, giving me a repository that could be imported by git-svn without any issues.

    Git Baby is a git and github fan, let's start git clone.