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.

  • Is it possible to add file to multiple git repos at the same time?
  • Undo a git push on the remote branch without changing local repository?
  • Subdirectory ignored in .gitignore whitelist
  • how to automatically compile class files after push to git
  • Incrementing Maven Project Version with Jenkins/Git
  • How do I make git show diff when rewording a commit message during rebase -i?
  • 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.

  • How can I use git for a framework and for a project using that framework while keeping the project separate?
  • Push Git branches directly into a live server directory so files are seen live
  • Git corrupted repo: how to pick a git object from a clean repository
  • Lost commit history for a branch in octopus merge
  • Amazon secret keys and Heroku
  • Can't commit changes to local git repository
  • 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
    
    PROPS-END
    

    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
    
    PROPS-END
    

    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.