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

Re: Joining Repositories

From
RARyan Anderson <ryan@michonline.com>
Date
Jan 18, 2006, 14:09 UTC
Message-ID
<20060118140917.GA15438@mythryan2.michonline.com>
In-Reply-To
<20060118125158.GN28365@pasky.or.cz>
On Wed, Jan 18, 2006 at 01:51:58PM +0100, Petr Baudis wrote:
Show 34 quoted lines
>   Hello,
> 
> Dear diary, on Wed, Jan 18, 2006 at 01:25:59PM CET, I got a letter
> where Mathias Waack <Mathias.Waack@rantzau.de> said that...
> > we're using git with cogito as a frontend. For some reasons I forgot we have 
> > some repositories which belong to the same project. To simplify the whole 
> > thing I would like to join these repositories. It mainly means to move some 
> > directories. So lets say I have: 
> > 
> > 	/r1/.git
> > 	/r2/.git
> > 
> > and what I would like to have is
> > 
> > 	/r/.git
> > 	   r1
> >            r2
> > 
> > Of course the history should remain (otherwise it would be to easy). 
> > 
> > How should I do this?
> 
>   The crucial question is what the joined repository's directory
> structure should be. If from r1/a, r2/b you want r/a, r/b then it's
> easy:
> 
> 	cd r1
> 	cg-branch-add r2 ../r2/.git
> 	cg-fetch r2
> 	cg-merge -j r2
> 
>   But if you want r1/a, r2/b to turn to r/r1/a, r/r2/b, you will have
> to rewrite the history of each (and then do the above). One rough
> and untested sketch...
... Why would that be the optimal method?

Assuming both repositories are clean, no extraneous files, and without testing, of course:

In r1:
	mkdir r1
	# move everything into the subdirectory called r1.
	git mv $(ls -a | grep -v -e ^.git$ -e ^r1$) r1/
	git commit -a "Restructure directory"
In r2:
	mkdir r2
	# move all files into r2/
	git mv $(ls -a | grep -v -e ^.git$ -e ^r2$) r2/
	git commit -a "Restructure directory"
	git fetch ../r1/
	GIT_INDEX_FILE=.git/tmp-index git-read-tree FETCH_HEAD
	GIT_INDEX_FILE=.git/tmp-index git-checkout-cache -a -u
	git-update-cache --add -- $(GIT_INDEX_FILE=.git/tmp-index git-ls-files)
	cp .git/FETCH_HEAD .git/MERGE_HEAD
	git commit

No history rewritten, merging with the old repositories should, at least theoretically, work, etc.

(This is just a restatement of Linus's "Coolest merge ever" / union merge)

-- 
Ryan Anderson
  sometimes Pug Majere
Previous: Andreas EricssonNext: Petr Baudis
Message 9 of 25 in “Joining Repositories”
  1. Mathias WaackJan 18, 2006
  2. Petr BaudisJan 18, 2006
  3. Petr BaudisJan 18, 2006
  4. Mathias WaackJan 18, 2006
  5. Petr BaudisJan 18, 2006
  6. Mathias WaackJan 19, 2006
  7. Junio C HamanoJan 19, 2006
  8. Andreas EricssonJan 18, 2006
  9. Ryan AndersonJan 18, 2006
  10. Petr BaudisJan 18, 2006
  11. Ryan AndersonJan 18, 2006
  12. Linus TorvaldsJan 18, 2006
  13. Petr BaudisJan 18, 2006
  14. Junio C HamanoJan 18, 2006
  15. Linus TorvaldsJan 18, 2006
  16. Junio C HamanoJan 18, 2006
  17. Linus TorvaldsJan 18, 2006
  18. Junio C HamanoJan 18, 2006
  19. Linus TorvaldsJan 18, 2006
  20. Linus TorvaldsJan 18, 2006
  21. Linus TorvaldsJan 18, 2006
  22. Junio C HamanoJan 19, 2006
  23. Petr BaudisJan 19, 2006
  24. Ryan AndersonJan 18, 2006
  25. H. Peter AnvinJan 18, 2006

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.