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

Re: [PATCH] docs: Clarify what git-rebase's "--preserve-merges" does

From
SOSergey Organov <s.organov@javad.com>
Date
Apr 1, 2015, 11:27 UTC
Message-ID
<87vbhgks0v.fsf@javad.com>
In-Reply-To
<xmqq8uedrtdb.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 47 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> I wonder if it will be the right way to get a correct result to
>> apply the difference to go from B to Z on top of an old commit when
>> you are side-porting.
>>
>> Imagine you want to backport the same X-Y history by redoing the
>> merge Z on top of another child of O (i.e. A's sibling).  That is,
>> you start from this:
>>
>>
>>          X---Y
>>         /     \
>>    O---A---B---Z---
>>     \
>>      M---N
>>
>> and would want to create this:
>>     
>>     
>>    O           X'--Y'
>>     \         /     \    
>>      M---N---A'--B'--Z'--
>>
>> As long as everything down to the merge-base of the parents of the
>> original merge (in this example, merge-base across Y and B that are
>> Z's parents, which is A) is being transplanted, "apply the
>> difference going from B to Z, on top of B', to obtain Z'" should
>> work, I would think.
>
> And just after I send the message because I needed to catch a bus, I
> notice that there is a problem.
>
> Actually, "replay diff going from B to Z instead of merging" must be
> done very carefully.  Imagine when Y in the original history were a
> cherry-pick of M.  What you would be creating would look more like
> this instead:
>      
>     O           X'--.
>      \         /     \    
>       M---N---A'--B'--Z'--
>
> because Y' becomes a no-op, as the transplanted history already has
> M applied.  But the original "diff going from B to Z" has the effect
> of M already in there.  You would end up adding the same hunk twice
> without noticing. You somehow need to come up with a way to deal
> with this.
Nope. It seems like cherry-pick takes care of that:

[SCRIPT] git init t; cd t; git config rerere.enabled false

cat > a <<EOF Line01 Line02 Line03 Line04 Line05 Line06 Line07 Line08 Line09 EOF

git add a git commit -aqm "A"

git checkout -b two-chunks sed -i -e 's/Line04/Line04_1/' a sed -i -e 's/Line08/Line08_1/' a git commit -aqm "A_04_08_1"

git checkout master sed -i -e 's/Line04/Line04_1/' a git commit -aqm "A_04_1"

git cherry-pick two-chunks

git log --oneline cat a [/SCRIPT]

What do I miss?
-- Sergey.
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 19 in “docs: Clarify what git-rebase's "--preserve-merges" does”
  1. docs: Clarify what git-rebase's "--preserve-merges" doesSebastian Schuberth, Mar 26, 2015
  2. Junio C HamanoMar 26, 2015
  3. Sebastian SchuberthMar 26, 2015
  4. Junio C HamanoMar 26, 2015
  5. Sergey OrganovMar 26, 2015
  6. Johannes SixtMar 26, 2015
  7. Sergey OrganovMar 31, 2015
  8. Junio C HamanoMar 31, 2015
  9. Sergey OrganovMar 31, 2015
  10. Junio C HamanoMar 31, 2015
  11. Sergey OrganovApr 1, 2015
  12. Junio C HamanoApr 1, 2015
  13. Sergey OrganovApr 2, 2015
  14. Sebastian SchuberthMar 30, 2015
  15. Junio C HamanoMar 30, 2015
  16. Sebastian SchuberthMar 30, 2015
  17. Junio C HamanoMar 30, 2015
  18. Junio C HamanoMar 30, 2015
  19. Sebastian SchuberthMar 30, 2015

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.