views:

233

answers:

1

I have this git repository which contains to folders binary-search and poker: http://github.com/soulnafein/code-katas

I would like to make this folders two submodules and I would like to keep the change history. How can I do that?

+1  A: 

The general idea is to use 'git filter-branch' and the following steps:

1) Create a submodule using --subdirectory-filter of filter-branch (after cloning your repo).

$ git filter-branch --subdirectory-filter ABC HEAD -- --all

See this SO question for more on this step.

2) Create a superproject using an index filter of filter-branch to delete the submodule.

$ git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch ABC" --prune-empty HEAD

3) Commit the submodule to the latest version of the superproject.

See Detach subdirectory into separate git repository for a practical example.

Each submodule will keep its history.
But as said in this patch proposal, it would:

lose all the historical connections between the superproject and the submodule, breaking tools like 'git bisect', and making it difficult to recover old releases.

Ideally, each version of the newly created superproject would be linked to the correct version of the submodule (and all the .gitmodules entries would be set up correctly, too, throughout the project's history)

If you do not need to have previous history linked to the new submodules, you can follow the steps mentioned above.
But if you do need to branch from an older point while have references to your submodules (which are currently simple sub-directories), the you could consider trying the script mentioned in the patch I refer to. It is discussed in this thread, but integrated to Git yet, as Junio C Hamano says:

Unfortunately, I do not think we have designed fully (nor implemented at all) behaviour to check out different points of history that has the same submodule moved around in the superproject tree.

VonC