threads / discuss / 16167

More help needed on merging unrelated repos

Subject: More help needed on merging unrelated repos

## tl;dr

8 messages between Nov 4, 2008 and Nov 6, 2008.

replies: 7people: 3as markdown or json

Christian MICHON· Nov 4, 2008, 13:14 UTC · lore
Hi,

I previously posted here a question on how to merge unrelated repos, and I was quite happy with the answer. git pull repo_name repo_branch

Yet, when I merge these repos (they're unrelated), I'd like to merge all of them at once.

How do I pull for example 2 repos in 1 command ? I cannot figure out the exact syntax to use.

I tried: git pull ../i1 0.5 ../i2 master git pull ../i1 0.5 -- ../i2 master

I also tried to play with --no-commit and -s to no avail.
Does anyone of you already use this and knows the trick ? Thanks in advance!
-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Andreas Ericsson· Nov 4, 2008, 20:12 UTC · re: Christian MICHON · lore

Re: More help needed on merging unrelated repos

Christian MICHON wrote:
Show 20 quoted lines
> Hi,
> 
> I previously posted here a question on how to merge unrelated repos,
> and I was quite happy with the answer.
> git pull repo_name repo_branch
> 
> Yet, when I merge these repos (they're unrelated), I'd like to merge
> all of them at once.
> 
> How do I pull for example 2 repos in 1 command ? I cannot figure out
> the exact syntax to use.
> 
> I tried:
> git pull ../i1 0.5 ../i2 master
> git pull ../i1 0.5 -- ../i2 master
> 
> I also tried to play with --no-commit and -s to no avail.
> 
> Does anyone of you already use this and knows the trick ? Thanks in advance!
> 

You can only pull from a single repository at a time. The first way of doing what you want that comes to mind is:

  git remote add lib1 lib1url
  git remote add lib2 lib2url
  git fetch lib1 && git fetch lib2 && git merge lib1/master lib2/master
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Christian MICHON· Nov 4, 2008, 21:08 UTC · re: Andreas Ericsson · lore

Re: More help needed on merging unrelated repos

Andreas Ericsson wrote:
Show 36 quoted lines
> Christian MICHON wrote:
>>
>> Hi,
>>
>> I previously posted here a question on how to merge unrelated repos,
>> and I was quite happy with the answer.
>> git pull repo_name repo_branch
>>
>> Yet, when I merge these repos (they're unrelated), I'd like to merge
>> all of them at once.
>>
>> How do I pull for example 2 repos in 1 command ? I cannot figure out
>> the exact syntax to use.
>>
>> I tried:
>> git pull ../i1 0.5 ../i2 master
>> git pull ../i1 0.5 -- ../i2 master
>>
>> I also tried to play with --no-commit and -s to no avail.
>>
>> Does anyone of you already use this and knows the trick ? Thanks in
>> advance!
>>
>
> You can only pull from a single repository at a time. The first way of doing
> what you want that comes to mind is:
>
>  git remote add lib1 lib1url
>  git remote add lib2 lib2url
>  git fetch lib1 && git fetch lib2 && git merge lib1/master lib2/master
>
> --
> Andreas Ericsson                   andreas.ericsson@op5.se
> OP5 AB                             www.op5.se
> Tel: +46 8-230225                  Fax: +46 8-230231
>
and apparently this strategy (which I tried before too :( ) fails when merging.

example: repo i1 contains file 'a' repo i2 contains file 'b' new repo z contains file 'readme' and I want to pull repo i1 and i2 at the same time inside repo z.

typically, I've to pull 1 repo at a time, if I use pull. If I fetch both without merge, and then I try a merge, it fails. maybe I'm on a wild goose chase after all.

thanks
-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Andreas Ericsson· Nov 4, 2008, 22:04 UTC · re: Christian MICHON · lore

Re: More help needed on merging unrelated repos

Christian MICHON wrote:
Show 48 quoted lines
> Andreas Ericsson wrote:
>> Christian MICHON wrote:
>>> Hi,
>>>
>>> I previously posted here a question on how to merge unrelated repos,
>>> and I was quite happy with the answer.
>>> git pull repo_name repo_branch
>>>
>>> Yet, when I merge these repos (they're unrelated), I'd like to merge
>>> all of them at once.
>>>
>>> How do I pull for example 2 repos in 1 command ? I cannot figure out
>>> the exact syntax to use.
>>>
>>> I tried:
>>> git pull ../i1 0.5 ../i2 master
>>> git pull ../i1 0.5 -- ../i2 master
>>>
>>> I also tried to play with --no-commit and -s to no avail.
>>>
>>> Does anyone of you already use this and knows the trick ? Thanks in
>>> advance!
>>>
>> You can only pull from a single repository at a time. The first way of doing
>> what you want that comes to mind is:
>>
>>  git remote add lib1 lib1url
>>  git remote add lib2 lib2url
>>  git fetch lib1 && git fetch lib2 && git merge lib1/master lib2/master
>>
>> --
>> Andreas Ericsson                   andreas.ericsson@op5.se
>> OP5 AB                             www.op5.se
>> Tel: +46 8-230225                  Fax: +46 8-230231
>>
> 
> and apparently this strategy (which I tried before too :( ) fails when merging.
> 
> example:
> repo i1 contains file 'a'
> repo i2 contains file 'b'
> new repo z contains file 'readme' and I want to pull repo i1 and i2 at
> the same time inside repo z.
> 
> typically, I've to pull 1 repo at a time, if I use pull. If I fetch
> both without merge, and then I try a merge, it fails.
> maybe I'm on a wild goose chase after all.
> 

Ah, right. Octopus merge always does merge head reduction, but to do that it needs to find a common ancestor. When no such ancestor exists, it will fail (with a message like "shouldn't be doing octopus merge"?).

If there's no "--no-reduce-heads" option to "git merge", I think you're screwed with getting that to happen in a single commit.

Oh wait.
git merge i1 && git merge --no-commit i2 && git commit --amend

might work. I'm still shooting from the hip though, and now it's far too late for me to think more. gl though.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Christian MICHON· Nov 4, 2008, 22:30 UTC · re: Andreas Ericsson · lore

Re: More help needed on merging unrelated repos

On Tue, Nov 4, 2008 at 11:04 PM, Andreas Ericsson <ae@op5.se> wrote:
Show 6 quoted lines
> Ah, right. Octopus merge always does merge head reduction, but to do
> that it needs to find a common ancestor. When no such ancestor exists,
> it will fail (with a message like "shouldn't be doing octopus merge"?).
>
> If there's no "--no-reduce-heads" option to "git merge", I think you're
> screwed with getting that to happen in a single commit.
:(
Show 8 quoted lines
>
> Oh wait.
>
> git merge i1 && git merge --no-commit i2 && git commit --amend
>
> might work. I'm still shooting from the hip though, and now it's far too
> late for me to think more. gl though.
>
it's late for me too!
$ git merge i1/master
Merge made by recursive.
 a |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a

$ git merge --no-commit i2/master Automatic merge went well; stopped before committing as requested

$ git commit --amend fatal: You are in the middle of a merge -- cannot amend.

note the merge can work, but it's still done in 2 steps. :( thanks for suggesting this.

-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Karl Hasselström· Nov 6, 2008, 08:37 UTC · re: Christian MICHON · lore

Re: More help needed on merging unrelated repos

On 2008-11-04 23:30:56 +0100, Christian MICHON wrote:
> note the merge can work, but it's still done in 2 steps. :(
> thanks for suggesting this.

If it had worked, you'd have gotten just one merge commit. What you want to do is entirely possible, but it seems the high-level commands were not designed with your use-case in mind.

Another thing you could try is to merge the two branches separately, getting a history like this:

  p1----\
         \
  p2---A--B
      /
  p3--

And then use grafts to convince git that B has parents p1, p2, and p3 (instead of its actual parents p1 and A). (Grep for "graft" in the Documentation directory.)

And then use git-filter-branch to rewrite history so that the grafted history becomes the real history.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Christian MICHON· Nov 6, 2008, 12:13 UTC · re: Karl Hasselström · lore

Re: More help needed on merging unrelated repos

On Thu, Nov 6, 2008 at 9:37 AM, Karl Hasselström <kha@treskal.com> wrote:
Show 29 quoted lines
> On 2008-11-04 23:30:56 +0100, Christian MICHON wrote:
>
>> note the merge can work, but it's still done in 2 steps. :(
>> thanks for suggesting this.
>
> If it had worked, you'd have gotten just one merge commit. What you
> want to do is entirely possible, but it seems the high-level commands
> were not designed with your use-case in mind.
>
> Another thing you could try is to merge the two branches separately,
> getting a history like this:
>
>  p1----\
>         \
>  p2---A--B
>      /
>  p3--
>
> And then use grafts to convince git that B has parents p1, p2, and p3
> (instead of its actual parents p1 and A). (Grep for "graft" in the
> Documentation directory.)
>
> And then use git-filter-branch to rewrite history so that the grafted
> history becomes the real history.
>
> --
> Karl Hasselström, kha@treskal.com
>      www.treskal.com/kalle
>

nice suggestion Karl! it took a while to understand all the consequences and workflow. On top of your suggestion, I had to remove the refs/original/refs/heads/master and the grafts file.

It worked well: quite a spell, but an efficient one. Kudo++
-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Karl Hasselström· Nov 6, 2008, 15:28 UTC · re: Christian MICHON · lore

Re: More help needed on merging unrelated repos

On 2008-11-06 13:13:42 +0100, Christian MICHON wrote:
> nice suggestion Karl! it took a while to understand all the
> consequences and workflow. On top of your suggestion, I had to
> remove the refs/original/refs/heads/master and the grafts file.

I've never tried to use git-filter-branch, so I was deliberately vague. I was hoping you would be the enterprising type who would figure out the details anyway ... ;-)

> It worked well: quite a spell, but an efficient one. Kudo++

Well, that's Git for you. Once you get the (really simple) underlying data model you know what _can_ be done, even if it's not always obvious _how_ to do it.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

← back to recent threads