How to fix branches of partial directory structure in SVN to Git migration

I’m trying to convert an SVN repository containing a Java EE application into a Git repository. The original repository contains a folder for each part of the Java EE project which has been maintained as separate projects history-wise. For two of the projects there’s also a “production”-branch (again, two separate branches) and whenever a new revision goes into production trunk is merged up into production.

When I import this into one single git repository (as I understand would be best practice) everything in master is fine, but when I switch to a branch I only get the files of that branch and most of the other folders and files disappear.

  • Show local commits when branch name contains slash
  • Where are the Git branches stored?
  • Is there one git command to create a branch, switch to it, and link it to it's remote counterpart?
  • Determining why github says “Closed with unmerged commits”
  • Why does a 'git pull' not also update the remote branch I pulled from?
  • SVN Mergeinfo properties on paths other than the working copy root
  • Repository layout:


    I found a post by Eric Gwin about this issue, but I couldn’t see there was any solutions to it.

    I might be overlooking something very elementary here, but I do fear that the only solution is to import the projects separetely? Any suggestions to how I can import the whole SVN-repo and get working branches in Git?

  • Importing Alamofire 3.4 - No such module 'Alamofire'
  • Git Recover local repository - accidentally did git clean -f -d
  • Rebasing pushed commits if only on personal branch
  • Git diff partial file name
  • git checkout error: unable to create file
  • Have git rerere automatically mark files as resolved?
  • One Solution collect form web for “How to fix branches of partial directory structure in SVN to Git migration”

    Initial situation

    After converting this to a single repository, the directory structure in master (or trunk) looks like this:


    The structure after the first commit of the project3-production-branch looks either like this:


    Or it contains the contents of project3 directly:


    This depends on where the branch was copied from in Subversion.

    In the first case, the next step can be skipped.

    In both cases, all other projects were removed on the branch (you should see that in the diff of the first commit) and need to be restored, see second step.

    Step 1: Rewrite branch to move all contents into subdirectory (if needed)

    See example “To move the whole tree into a subdirectory” in filter-branch and execute that only on the branch, like so:

    git filter-branch --index-filter \
        'git ls-files -s | sed "s-\t\"*-&project3/-" |
            GIT_INDEX_FILE=$ \
                git update-index --index-info &&
         mv "$" "$GIT_INDEX_FILE"' \

    Step 2: Rewrite branch to restore other projects

    In this step we want to undo the removal of the other projects in the first branch commit. This can be done using the following:

    parent=`git merge-base $branch master` # or replace master with trunk if needed
    paths="project1 project2 project4"
    git filter-branch -f --index-filter \
    "git reset -q $parent -- $paths" --tag-name-filter cat -- \

    It resets the other paths to the state they were in when the branch was created, for all commits from the branch.

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