{"thread":{"id":"34893","subject":"Git: Having trouble merging two repositories by interweaving their histories","startedAt":"2013-09-09T21:26:42Z","lastAt":"2013-09-10T00:19:46Z","messageCount":3,"participants":["THILLOSEN Andreas","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"227266","messageId":"522E3D12.4090004@free.fr","threadId":"34893","inReplyTo":null,"subject":"Git: Having trouble merging two repositories by interweaving their histories","fromName":"THILLOSEN Andreas","fromEmail":"thillosen@free.fr","sentAt":"2013-09-09T21:26:42Z","receivedAt":"2013-09-09T21:26:42Z","isPatch":false,"sender":{"key":"thillosen@free.fr","avatar":null},"body":"Hi,\n\nI recently stumbled over problems, while trying to merge two\nrepositories (RepA and RepB) into a single one (RepM).\nI must mention that indexed files in RepA are totally distinct from\nindexed files in RepB, thus no conflict shall appear.\nThe problem is that I never manage to get the exact result I'm hoping for:\n\n1] RepM should have the entire commit histories of both RepA and RepB.\n2] In RepM, indexed files should be separated in two directories:  DirA\n(for files associated to RepA), and DirB (for files associated to RepB).\n3] I should be able to bissect easily within the history of RepM, even\nfor old commits. It implies that if I checkout a particular commit\n(initially associated to RepA), indexed files initially associated to\nRepA and RepB should get updated (and not only files associed to RepA).\nIt implies \"interweaving\" their histories, so that I can get a \"state\"\nof both RepA and RepB around a same time period of time.\n\nFor my scenario, I used these kinds of commands (from a git bash\nlaunched within an initialized repository RepM):\n\ngit remote add RepA /path/RepA\ngit fetch RepA\ngit checkout -b RepA/master\ngit merge -s recursive -Xsubtree=DirA RepA/master\n\ngit remote add RepB /path/RepB\ngit fetch RepB\ngit checkout -b RepB/master\ngit merge -s recursive -Xsubtree=DirB RepB/master\n\nWith these commands, only my first point 1] is satisfied (I can see the\nfull history associated to RepA and RepB).\n\nIf I checkout RepM to an old commit, the files indexed by RepA or RepB\nare updated by ignoring the directories DirA and DirB (point 2] is not\nsatisfied).\n\nMoreover, only files associated to either RepA or RepB (depending on the\norigin of the commit) get updated (point 3] is not satisfied).\nIn history, commits from RepA are all appearing at the beginning, and\ncommits from RepB are appearing at the end (they are clearly being\nseparated).\nShould \"rebase\" help me to solve this? With what kind of parameters?\n\nGreetings,\n\nAndreas THILLOSEN.\n"},{"id":"227284","messageId":"87fvtdbnna.fsf@igel.home","threadId":"34893","inReplyTo":"522E3D12.4090004@free.fr","subject":"Re: Git: Having trouble merging two repositories by interweaving their histories","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2013-09-09T23:06:49Z","receivedAt":"2013-09-09T23:06:49Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"THILLOSEN Andreas <thillosen@free.fr> writes:\n\n> It implies \"interweaving\" their histories, so that I can get a \"state\"\n> of both RepA and RepB around a same time period of time.\n\nThis is only possible by rewriting every commit to point to a new tree\ncontaining the combined trees of the two repositories.  To get a\nmeaningful result this requires that both repositories have a completely\nlinear history.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"227288","messageId":"522E65A2.3060401@free.fr","threadId":"34893","inReplyTo":"87fvtdbnna.fsf@igel.home","subject":"Re: Git: Having trouble merging two repositories by interweaving their histories","fromName":"THILLOSEN Andreas","fromEmail":"thillosen@free.fr","sentAt":"2013-09-10T00:19:46Z","receivedAt":"2013-09-10T00:19:46Z","isPatch":false,"sender":{"key":"thillosen@free.fr","avatar":null},"body":"Le 09/10/13 01:06, Andreas Schwab a écrit :\n> THILLOSEN Andreas <thillosen@free.fr> writes:\n> \n>> It implies \"interweaving\" their histories, so that I can get a \"state\"\n>> of both RepA and RepB around a same time period of time.\n> \n> This is only possible by rewriting every commit to point to a new tree\n> containing the combined trees of the two repositories.  To get a\n> meaningful result this requires that both repositories have a completely\n> linear history.\n> \n> Andreas.\n> \n\nThanks for your answer...\n\nI searched a little more around the web, and found some trick called\n\"grafting repositories\".\nBut examples were all of the same kind: They supposed that all commits\nin RepA were done before commits in RepB. For instance:\n\nhttp://stackoverflow.com/questions/2428137/how-to-rebase-one-git-repository-onto-another-one\n\nThis is not my case, because I had work done in parallel in both\nrepositories.\nSo I'm not really sure that \"grafting\" could help in my particular case...\n\nTo make the graft permanent, they use git filter-branch, which rewrites\nhistory (all SHA1s are changed etc.)... but as long as dates could be\nkept, it would not annoy me that much.\n\nI also found a script called git-stitch-repo in CPAN... I have not yet\ntested it, but it is reported that it only works on repositories with\nlinear history (no merges):\nhttp://search.cpan.org/~book/Git-FastExport-0.09/script/git-stitch-repo\n\nThis is also not my case: Merges have been done regularly on my two\nrepositories...\n\nThere is also this tool: CombineRepo... no idea how reliable it is, or\nwhat limitations it entails:\nhttps://github.com/geppo12/GitCombineRepo\n\nSo... if I understand correctly, there will be no real practical way to\nmerge my two repositories, in order to get an interweaving history? (not\ncriticizing, I only want to know where I am heading now!)\n\nGreetings,\n\nAndreas THILLOSEN.\n"}]}