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.
/ trunk/ project1/ project2/ project3/ project4/ branches/ project3-production-branch/ project4-production-branch/ tags/
I found a post by Eric Gwin about this issue, but I couldn’t see there was any solutions to it. http://comments.gmane.org/gmane.comp.ide.eclipse.git/77
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?
One Solution collect form web for “How to fix branches of partial directory structure in SVN to Git migration”
After converting this to a single repository, the directory structure in master (or trunk) looks like this:
project1/ project2/ project3/ project4/
The structure after the first commit of the
project3-production-branch looks either like this:
Or it contains the contents of project3 directly:
.project src/ test/
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_INDEX_FILE.new \ git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' \ master..project3-production-branch
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:
branch="project3-production-branch" 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 -- \ $parent..$branch
It resets the other paths to the state they were in when the branch was created, for all commits from the branch.