public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Julien Maurel <julien@maurel.me>
Cc: git@vger.kernel.org
Subject: Re: Question about merge & cherry pick
Date: Thu, 7 Nov 2024 07:37:19 +0100	[thread overview]
Message-ID: <eb367098-0c88-4bc6-b824-32ee6e6d273e@kdbg.org> (raw)
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


  reply	other threads:[~2024-11-07  6:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 20:24 Question about merge & cherry pick Julien Maurel
2024-11-07  6:37 ` Johannes Sixt [this message]
2024-11-07 10:32   ` Julien Maurel
2024-11-07 12:02     ` brian m. carlson
2024-11-07 17:18     ` Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb367098-0c88-4bc6-b824-32ee6e6d273e@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=julien@maurel.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox