views:

100

answers:

1

As a subset of the question detach-subdirectory already made before and considering the fact that even though a lot of questions were made about the process of splitting and merging git repositories, I couldn't find one that touches the subject of splitting when submodules are present.

So in the following scenario:

.git/
.gitmodules
folder/
    data/
    content/
        other_data/
        submoduleA/
        submoduleB/

I would like to get two repositories with the following structure:

.git/
data/

and

.git/
.gitmodules
content/
    other_data/
    submoduleA/
    submoduleB/

The first case is not a problem and can be solved easily with the method described in detach-subdirectory.

The second not so much. The existence of submodules and the fact that .gitmodules contains the full path for folder/content/submoduleA and folder/content/submoduleB causes part of the history to be inconsistent since .gitmodules refers to a nonexistent directory structure (once filter-branch is used).

So I would like to know if there is a way to do this without causing inconsistent history.

+1  A: 

I suspect (not tested) that a second git filter-branch would have the opportunity to modify the .gitmodules content for each commits of the new repo.

But actually a git submodule split command was in discussion early 2009.

Proposed usage:

git submodule split [--url submodule_repo_url] submodule_dir \
    [alternate_dir...]

Replace submodule_dir with a newly-created submodule, keeping all the history of submodule_dir.
This command also rewrites each commit in the current repository's history to include the correct revision of sumodule_dir and the appropriate .gitmodules entries.

However, I don't see it in the latest what's cooking.
The script in the proposed patch can give you an idea of the kind of tree rewriting necessary to update the .gitmodules file though.

VonC
Using a second git filter-branch command I was able to rewrite .gitmodules with a sed command, however the actual submodule folders are still left untouched (both with index-filter and tree-filter). Only subdirectory-filter was able to change them but then .gitmodules is removed.The git submodule split command seems to do exactly what I intend, but reading the thread I got the impression that it has a few problems so I don't feel comfortable using it.
Unode
@Unode: I understand. I don't think this particular patch is in active development right now.
VonC