git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Merging submodules

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Jul 30, 2008, 22:59 UTC
Message-ID
<20080730225939.GA6471@Hermes>
This message got eaten by a syntax error somewhere.  This is a re-send, sorry for any duplicate messages.
On Jul 30, 2008, at 9:58 AM, H.Merijn Brand wrote:
Show 14 quoted lines
> 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
> 
> /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

>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
Message 1 of 1 in “Merging submodules”
  1. Brian GernhardtJul 30, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.