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

Re: Joining Repositories

From
Linus Torvalds <torvalds@osdl.org>
Date
Jan 18, 2006, 16:23 UTC
Message-ID
<Pine.LNX.4.64.0601180813170.3240@g5.osdl.org>
In-Reply-To
<20060118140917.GA15438@mythryan2.michonline.com>
On Wed, 18 Jan 2006, Ryan Anderson wrote:
Show 24 quoted lines
>
> 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,
Right.
> merging with the old repositories should, at least theoretically, work, 
> etc.

No. This - and the history rewriting - both have a fundamental problem: it becomes totally impossible to merge back any changes of the subprojects, at least automatically. The renaming just ends up making pretty much any merge a manual affair (git can _help_, but it's going to be a matter of luck if it works or not - and it usually won't work very well, because you'll probably end up having files that have the same name in the new and the old repo, and eventually you'll just have tons of confusion).

So it works only if you want to _really_ join the projects (like in the "git tools" case), and never touch the old one again but it sucks otherwise.

In the "gitk" case, we could actually continue to merge stuff after a join, but that was largaly because there was no renaming. That's a very special case, and it also became impossible to merge back.

Now, let's see what Junio comes up with, but in the meantime, I'd almost suggest just something like

	git clone oldrepo r1
	cd r1
	git checkout -b join-branch
	cd ..
	git add r1/.git/refs/heads/join-branch
	git commit -m "Join repo 'oldrepo' at 'r1'"

which should actually work except for the fact that we don't like the ".git" component even as part of a sub-component (ie small hack to git required to make it not ignore that path).

		Linus
Previous: Ryan AndersonNext: Petr Baudis
Message 12 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.