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

Re: How-to combine several separate git repos?

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Dec 10, 2007, 06:51 UTC
Message-ID
<Pine.LNX.4.64.0712100137250.5349@iabervon.org>
In-Reply-To
<475CDE73.9010505@saville.com>
On Sun, 9 Dec 2007, Wink Saville wrote:
> Daniel,
> 
> Worked like a charm, someday maybe I'll understand why it works:)
I should probably explain (now that I know it's actually relevant).
> > # Add a project "foo"
> > $ git fetch ../foo refs/heads/master:refs/heads/foo

Get the history and data, as an extra branch, so we can deal with it easily.

> > $ git merge --no-commit foo

We want to generate a merge commit, but we want to mess with it, so we use merge to set it up, but --no-commit to not actually commit it. (The commit below will generate a merge commit if we don't cancel stuff entirely.)

> > $ git read-tree --reset -u HEAD

Replace the index (--reset), updating the working directory (-u), with HEAD (the commit on the local side before the merge we're in the middle of).

> > $ git read-tree -u --prefix=foo/ foo

Read into the index, updating the working directory, "foo" (the branch we fetched above), but with the prefix "foo/" so everything is stuffed into a subdirectory.

> > $ git commit

And commit the result, which has the tree as constructed above (everything from the local parent, and everything from the branch in a subdirectory), and has the parents as for the merge we started: first parent is the local line without the additional branch, and the second parent is the added repository.

And git doesn't care about global structure, so the fact that this commit is obviously just what you'd ideally like, while the history as a whole is a bit odd (like, it doesn't have a unique start, and development didn't start in subdirectories, and...) doesn't matter.

	-Daniel
*This .sig left intentionally blank*
Previous: Wink SavilleNext: Wink Saville
Message 10 of 13 in “How-to combine several separate git repos?”
  1. Wink SavilleDec 9, 2007
  2. Alex RiesenDec 9, 2007
  3. Wink SavilleDec 9, 2007
  4. Daniel BarkalowDec 9, 2007
  5. Wink SavilleDec 9, 2007
  6. Daniel BarkalowDec 10, 2007
  7. Wink SavilleDec 10, 2007
  8. Daniel BarkalowDec 10, 2007
  9. Wink SavilleDec 10, 2007
  10. Daniel BarkalowDec 10, 2007
  11. Wink SavilleDec 10, 2007
  12. Alex RiesenDec 10, 2007
  13. Wink SavilleDec 10, 2007

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.