Skip to contentSkip to conversation

Merging submodules

DISCUSSION Brian Gernhardt 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

This message got eaten by a syntax error somewhere. This is a re-send, sorry for any duplicate messages.

Quoted 7 lines · H.Merijn Brand

One (very) big disadvantage of SCCS is that commits are on a per-file basis, and only in a single directory. This drawback still haunts me in git, as my first attempts to convert were successful in a single folder and git cannot merge folders into a single project.

Say I now have

Quoted 7 lines

/work/src/project/.git
/work/src/project/module_a/.git
/work/src/project/module_b/.git
/work/src/project/module_c/.git

Which are all converted repos from SCCS, I'd like to merge the three module_# repos into the top level repo.

Following the example of Linus, the following is completely untested.

First you fetch all of the heads/tags/etc into the superproject with commands like

git fetch module_a refs/heads/*:refs/remotes/module_a/* git fetch module_b refs/heads/*:refs/remotes/module_b/*
git fetch module_c refs/heads/*:refs/remotes/module_c/*

Then you do something like:

rm -rf module_{a,b,c}/.git # Do this in a test repository, obviously... git add module_a module_b module_c
git commit # Needed because '-s ours' uses current HEAD, not index git merge --no-commit -s ours module_a/master module_b/master module_c/master git commit --amend

Quoted 1 line

From this point on, the project repository has a merged history of the sub-projects, and if anyone doesn't catch up and still makes a commit on a subproject you can use "git merge -s subtree" to merge it in anyway.

You may need to "git rm --cached" some files after the "git add" step if your .gitignore files aren't perfect.

~~ Brian