Search code examples
gitgit-svngit-subtree

Split subdirectories into separate branch


I am trying to import my SVN project into Git. I have the following directory structure in SVN:

trunk
  -- AAA
  -- UUU
  -- PPP
  -- QQQ

In Git, I want this to be:

master branch
  -- AAA
  -- UUU
PQ-branch
  -- PPP
  -- QQQ

How do I achieve this while preserving all commit history for the directories?

I tried using Git subtree split to split PPP and QQQ into separate branches but how do I delete the commit history for PPP and QQQ from the master branch?

I tried using filter-branch with --tree-filter but that didn't help.


Solution

  • You can use git svn clone to clone different subdirectories separately as branches. Once you have this ready, the tricky part starts which is to rewrite git history where you stitch/join two branches, AAA and UUU, as master and rest as branch PQ.

    You can use git graft or git replace to do this. Be careful as you are rewriting git history. You can read more information here at https://git.wiki.kernel.org/index.php/GraftPoint or https://git-scm.com/blog/2010/03/17/replace.html.

    To find the graft point you will need to find the last common commit between two branches (AAA and UUU) which is your graft point. The easiest way to find out this is to search for commit with the same timestamp in both branches. Once you find this commit, you have your graft point