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

Re: Question about merge & cherry pick

From
Johannes Sixt <j6t@kdbg.org>
Date
Nov 7, 2024, 06:37 UTC
Message-ID
<eb367098-0c88-4bc6-b824-32ee6e6d273e@kdbg.org>
In-Reply-To
<711a0faa-6d82-48b6-819d-9ddbeda03f6a@maurel.me>
Am 06.11.24 um 21:24 schrieb Julien Maurel:
> From my point of view, after these operations, content on branch master
> and dev should be same with "zZz" on second line and "eDe" on last one.
> But it's not the case on second line...
The behavior that you observe is as intended and not a bug.
You have this (consider each letter on its own line):
          A Z Q E       initial commit
         /       \
     A Y Q E      |     dev: Z -> Y
        |         |
        |     A Y Q E   master: cherry-pick Z -> Y
        |         |
     A Z Q D      |     dev: revert Y -> Z and change E -> D
         \        /
          A Y Q D       merge

Your expectation that the merge result is "A Z Q D" is wrong. Consider what happened on the dev branch (left) since the branches diverged: Since the change from Z to Y was reverted to Z, the only change that the dev side contributes to the merge is that of E to D. The master side, on the other hand, contributes the change of Z to Y. So the total of the merge must be Z to Y from the master side and E to D from the dev side, and that is what you get.

A merge does not consider the individual changes on the branches, but only the differences since the merge base. For the merge operation, the change from Z to Y never happened on the dev side. The reversal of Y to Z is not visible for the merge and cannot contribute to the result.

-- Hannes
Previous: Julien MaurelNext: Julien Maurel
Message 2 of 5 in “Question about merge & cherry pick”
  1. Julien MaurelNov 6, 2024
  2. Johannes SixtNov 7, 2024
  3. Julien MaurelNov 7, 2024
  4. brian m. carlsonNov 7, 2024
  5. Johannes SixtNov 7, 2024

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.