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

Re: merge maintaining history

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 19, 2017, 21:42 UTC
Message-ID
<xmqq37gezpz8.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<5880BB23.8030702@comcast.net>
"David J. Bakeman" <nakuru@comcast.net> writes:
Show 21 quoted lines
>> So you want to merge the "new" history into the original tree now, so
>> you checkout the original tree, then "git merge <new-remote>/<branch>"
>> and then fix up any conflicts, and then git commit to create a merge
>> commit that has the new history. Then you could push that to both
>> trees.
>>
>> I would want a bit more information about your setup before providing
>> actual commands.
>
> Thanks I think that's close but it's a little more complicated I think
> :<(  I don't know if this diagram will work but lets try.
>
> original A->B->C->D->E->F
>              \
> first branch  b->c->d->e
>
> new repo e->f->g->h
>
> Now I need to merge h to F without loosing b through h hopefully.  Yes e
> was never merged back to the original repo and it's essentially gone now
> so I can't just merge to F or can I?

With the picture, I think you mean 'b' is forked from 'B' and the first branch built 3 more commits on top, leading to 'e'.

You say "new repo" has 'e' thru 'h', and I take it to mean you started developing on top of the history that leads to 'e' you built in the first branch, and "new repo" has the resulting history that leads to 'h'.

Unless you did something exotic and non-standard, commit 'e' in "new repo" would be exactly the same as 'e' sitting on the tip of the "first branch", so the picture would be more like:

Show 5 quoted lines
> original A->B->C->D->E->F
>              \
> first branch  b->c->d->e
>                         \
> new repo                 f->g->h

no? Then merging 'h' into 'F' will pull everything you did since you diverged from the history that leads to 'F', resulting in a history of this shape:

Show 5 quoted lines
> original A->B->C->D->E->F----------M
>              \                    /
> first branch  b->c->d->e         /
>                         \       /
> new repo                 f->g->h

If on the other hand you did something non-standard and exotic to rewrite 'e' at the end of "first branch" and make a different commit that does not even have any parent in "new repo", and the history of "new repo" originates in such a commit that is not 'e', things will become messy. But I didn't think I read you did anything unusual so a simple "git checkout F && git merge h" should give you what you want.

Previous: David J. BakemanNext: Jakub Narębski
Message 4 of 9 in “merge maintaining history”
  1. David J. BakemanJan 14, 2017
  2. Jacob KellerJan 15, 2017
  3. David J. BakemanJan 19, 2017
  4. Junio C HamanoJan 19, 2017
  5. Jakub NarębskiJan 20, 2017
  6. Junio C HamanoJan 20, 2017
  7. David J. BakemanJan 26, 2017
  8. Jacob KellerJan 26, 2017
  9. Philip OakleyJan 19, 2017

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.