git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Igor Djordjevic <igor.d.djordjevic@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>,
	Jacob Keller <jacob.keller@gmail.com>,
	Sergey Organov <sorganov@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [RFC] Rebasing merges: a jorney to the ultimate solution (Road Clear)
Date: Wed, 28 Feb 2018 00:27:19 +0100 (STD)
Message-ID: <nycvar.QRO.7.76.6.1802272330290.56@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz> (raw)
In-Reply-To: <33da31e9-9101-475d-8901-4b6b3df2f29d@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 10495 bytes --]

Hi Buga,

thank you for making this a lot more understandable to this thick
developer.

On Tue, 27 Feb 2018, Igor Djordjevic wrote:

> On 27/02/2018 19:55, Igor Djordjevic wrote:
> > 
> > It would be more along the lines of "(1) rebase old merge commit parents, 
> > (2) generate separate diff between old merge commit and each of its 
> > parents, (3) apply each diff to their corresponding newly rebased 
> > parent respectively (as a temporary commit, one per rebased parent), 
> > (4) merge these temporary commits to generate 'rebased' merge commit, 
> > (5) drop temporary commits, recording their parents as parents of 
> > 'rebased' merge commit (instead of dropped temporary commits)".
> > 
> > Implementation wise, steps (2) and (3) could also be done by simply 
> > copying old merge commit _snapshot_ on top of each of its parents as 
> > a temporary, non-merge commit, then rebasing (cherry-picking) these 
> > temporary commits on top of their rebased parent commits to produce 
> > rebased temporary commits (to be merged for generating 'rebased' 
> > merge commit in step (4)).
> 
> For those still tagging along (and still confused), here are some 
> diagrams (following what Sergey originally described). Note that 
> actual implementation might be even simpler, but I believe it`s a bit 
> easier to understand like this, using some "temporary" commits approach.
> 
> Here`s our starting position:
> 
> (0) ---X1---o---o---o---o---o---X2 (master)
>        |\
>        | A1---A2---A3
>        |             \
>        |              M (topic)
>        |             /
>        \-B1---B2---B3
> 
> 
> Now, we want to rebase merge commit M from X1 onto X2. First, rebase
> merge commit parents as usual:
> 
> (1) ---X1---o---o---o---o---o---X2
>        |\                       |\
>        | A1---A2---A3           | A1'--A2'--A3'
>        |             \          |
>        |              M         |
>        |             /          |
>        \-B1---B2---B3           \-B1'--B2'--B3'
> 
> 
> That was commonly understandable part.

Good. Let's assume that I want to do this interactively (because let's
face it, rebase is boring unless we shake up things a little). And let's
assume that A1 is my only change to the README, and that I realized that
it was incorrect and I do not want the world to see it, so I drop A1'.

Let's see how things go from here:

> Now, for "rebasing" the merge commit (keeping possible amendments), we
> do some extra work. First, we make two temporary commits on top of old
> merge parents, by using exact tree (snapshot) of commit M:
> 
> (2) ---X1---o---o---o---o---o---X2
>        |\                       |\
>        | A1---A2---A3---U1      | A1'--A2'--A3'
>        |             \          |
>        |              M         |
>        |             /          |
>        \-B1---B2---B3---U2      \-B1'--B2'--B3'

Okay, everything would still be the same except that I still have dropped
A1'.

> So here, in terms of _snapshots_ (trees, not diffs), U1 = U2 = M.
> 
> Now, we rebase these temporary commits, too:
> 
> (3) ---X1---o---o---o---o---o---X2
>        |\                       |\
>        | A1---A2---A3---U1      | A1'--A2'--A3'--U1'
>        |             \          |
>        |              M         |
>        |             /          |
>        \-B1---B2---B3---U2      \-B1'--B2'--B3'--U2'

I still want to drop A1 in this rebase, so A1' is still missing.

And now it starts to get interesting.

The diff between A3 and U1 does not touch the README, of course, as I said
that only A1 changed the README.  But the diff between B3 and U2 does
change the README, thanks to M containing A1 change.

Therefore, the diff between B3' and U2' will also have this change to the
README. That change that I wanted to drop.

> As a next step, we merge these temporary commits to produce our
> "rebased" merged commit M:
> 
> (4) ---X1---o---o---o---o---o---X2
>        |\                       |\
>        | A1---A2---A3---U1      | A1'--A2'--A3'--U1'
>        |             \          |                  \
>        |              M         |                   M'
>        |             /          |                  /
>        \-B1---B2---B3---U2      \-B1'--B2'--B3'--U2'

And here, thanks to B3'..U2' changing the README, M' will also have that
change that I wanted to see dropped.

Note that A1' is still dropped in my example.

> Finally, we drop temporary commits, and record rebased commits A3' 
> and B3' as our "rebased" merge commit parents instead (merge commit 
> M' keeps its same tree/snapshot state, just gets parents replaced):
> 
> (5) ---X1---o---o---o---o---o---X2
>        |\                       |\
>        | A1---A2---A3---U1      | A1'--A2'--A3'
>        |             \          |             \
>        |              M         |              M'
>        |             /          |             /
>        \-B1---B2---B3---U2      \-B1'--B2'--B3'

Now, thanks to U2' being dropped (and A1' *still* being dropped), the
change in the README that is still in M' is really only in M'. No other
rebased commit has it. That makes it look as if M' introduced this change
in addition to the changes that were merged between the merge parents.

This is what an "evil merge" is: it does more than just combine the
previously diverging branches. It introduces another change that was not
in any non-merge commits before it.

Sometimes, such an "evil merge" is necessary. For example, when master
converted a couple more `hash` references to `oid` including, say, in a
function signature, and the merged branch contains a new caller using that
old function signature: in this case, the merge commit must convert those
`hash` references to `oid` references, or the code won't compile.

In my example, where I dropped A1' specifically so that that embarrasingly
incorrect change to the README would not be seen by the world, though, the
evil merge would be truly evil: it would show said change to the world.
The exact opposite of what I wanted.

> And that`s it, our merge commit M has been "rebased" to M' :)
> 
> (6) ---X1---o---o---o---o---o---X2 (master)
>                                 |\
>                                 | A1'--A2'--A3'
>                                 |             \
>                                 |              M' (topic)
>                                 |             /
>                                 \-B1'--B2'--B3'
> 
> 
> Important thing to note here is that in our step (3) above, still in 
> terms of trees/snapshots (not diffs), U1' could still be equal to 
> U2', produced merge commit M' tree thus being equal to both of them 
> as well (merge commit introducing no changes to either of its 
> parents, originally described by Sergey as "angel merge").
> 
> But it doesn`t have to be so - if any of the rebased commits A1 to A3 
> or B1 to B3 was dropped or modified (or extra commits added, even), 
> that would influence the trees (snapshots) produced after rebasing U1 
> and U2 to U1' and U2', final merge M' reflecting all these changes as 
> well, besides keeping original merge commit M amendments (preserving 
> "evil merge").

Sadly, it would also introduce evil merges in certain circumstances, as I
demonstrated above.

> Well, that`s some theory, now to hopefully confirm/test/polish all 
> this... or trash it, if flawed beyond correction :P

It would have been nice to have such a simple solution ;-)

So the most obvious way to try to fix this design would be to recreate the
original merge first, even with merge conflicts, and then trying to use the
diff between that and the actual original merge commit. In your example,
this would look like that:

---X1---o---o---o---o---o---X2
   |\                       |\
   | A1---A2---A3--         | A1'--A2'--A3'
   |             \ \        |
   |              M M²      |
   |             / /        |
   \-B1---B2---B3--         \-B1'--B2'--B3'

Note that M² would be generated somewhat like this: `git checkout
A3; git merge -s recursive B3; git add -u; git commit`. If there are merge
conflicts, then the result would include the conflict markers.

Now we would generate something similar to those U1/U2 commits: a
single-parent commit R that reflects the diff between M and M²:

---X1---o---o---o---o---o---X2
   |\                       |\
   | A1---A2---A3           | A1'--A2'--A3'
   |             \          |
   |              M---R     |
   |             /          |
   \-B1---B2---B3           \-B1'--B2'--B3'

Note that the tree of R is identical to the tree of M². We can now
proceed to generate the merge between A3' and B3' (possibly with merge
conflicts) and then reverting R on top:

---X1---o---o---o---o---o---X2
   |\                       |\
   | A1---A2---A3           | A1'--A2'--A3'
   |             \          |              \
   |              M---R     |               M'---M³
   |             /          |              /
   \-B1---B2---B3           \-B1'--B2'--B3'

Of course, as before, the idea would be to squash the reverted
changes into the final merge commit.

Now, would this work?

I doubt it, for at least two reasons:

- if there are merge conflicts between A3/B3 and between A3'/B3', those
  merge conflicts will very likely look very different, and the conflicts
  when reverting R will contain those nested conflicts: utterly confusing.
  And those conflicts will look even more confusing if a patch (such as
  A1') was dropped during an interactive rebase.

- One of the promises was that the new way would also handle merge
  strategies other than recursive. What would happen, for example, if M
  was generated using `-s ours` (read: dropping the B* patches' changes)
  and if B1 had been cherry-picked into the history between X1..X2?

  Reverting R would obviously revert those B1 changes, even if B1' would
  obviously not even be part of the rebased history!

Yes, I agree that this `-s ours` example is quite concocted, but the point
of this example is not how plausible it is, but how easy it is to come up
with a scenario where this design to "rebase merge commits" results in
very, very unwanted behavior.

But maybe I missed something obvious, and the design can still be fixed
somehow?

Ciao,
Johannes

  reply index

Thread overview: 173+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-16 13:08 Sergey Organov
2018-02-18  4:16 ` Jacob Keller
2018-02-19  5:28   ` Sergey Organov
2018-02-19 23:44 ` Igor Djordjevic
2018-02-20 12:42   ` Sergey Organov
2018-02-27  0:07   ` Johannes Schindelin
2018-02-27  5:01     ` Sergey Organov
2018-02-27  5:30     ` Jacob Keller
2018-02-27 16:21       ` Johannes Schindelin
2018-02-27 18:55         ` Igor Djordjevic
2018-02-27 19:59           ` Igor Djordjevic
2018-02-27 23:27             ` Johannes Schindelin [this message]
2018-02-28  2:12               ` Igor Djordjevic
2018-02-28  4:35                 ` Igor Djordjevic
2018-02-28  6:14                   ` Sergey Organov
2018-02-28 20:53                     ` Igor Djordjevic
2018-02-28  5:44               ` Sergey Organov
2018-02-28 19:42                 ` Igor Djordjevic
2018-02-27 23:40             ` Igor Djordjevic
2018-02-28  0:10               ` Junio C Hamano
2018-02-28  2:35                 ` Igor Djordjevic
2018-02-28  5:27                 ` Sergey Organov
2018-02-28  0:36               ` Jacob Keller
2018-02-28  1:33                 ` Igor Djordjevic
2018-02-28  1:43                   ` Igor Djordjevic
2018-02-28  5:21                   ` Sergey Organov
2018-02-28 19:09                     ` Igor Djordjevic
2018-03-01  5:27                       ` Sergey Organov
2018-02-28  5:19               ` Sergey Organov
2018-02-28 20:25                 ` Igor Djordjevic
2018-02-28 22:17                   ` Igor Djordjevic
2018-03-01  5:19                     ` Sergey Organov
2018-03-01  5:39                   ` Sergey Organov
2018-03-02  1:16                     ` Igor Djordjevic
2018-03-02  5:40                       ` Sergey Organov
2018-03-02 17:45                         ` Igor Djordjevic
2018-03-02 11:17                       ` [RFC] Rebasing merges: a jorney to the ultimate solution(RoadClear) Phillip Wood
2018-03-02 12:36                         ` Phillip Wood
2018-03-02 16:02                           ` Jacob Keller
2018-03-02 23:33                             ` Igor Djordjevic
2018-03-06 10:36                               ` Phillip Wood
2018-03-06 18:12                                 ` Johannes Schindelin
2018-03-06 19:43                                   ` Igor Djordjevic
2018-03-07  7:26                                     ` Johannes Schindelin
2018-03-08 11:20                                       ` Phillip Wood
2018-03-08 12:16                                         ` Phillip Wood
2018-03-08 16:05                                           ` Igor Djordjevic
2018-03-11 12:00                                             ` Johannes Schindelin
2018-03-11 16:33                                               ` Igor Djordjevic
2018-03-12 10:37                                                 ` Johannes Schindelin
2018-03-12 12:56                                                   ` Sergey Organov
2018-03-13  0:01                                                     ` Igor Djordjevic
2018-03-26 12:03                                                       ` Johannes Schindelin
2018-03-27  5:08                                                         ` Sergey Organov
2018-03-27 13:35                                                           ` Johannes Schindelin
2018-04-02  6:07                                                             ` Sergey Organov
2018-03-12 23:54                                                   ` Igor Djordjevic
2018-03-13  6:25                                                     ` Sergey Organov
2018-03-08 15:56                                         ` Igor Djordjevic
2018-03-11 12:08                                           ` Johannes Schindelin
2018-03-11 17:34                                             ` Igor Djordjevic
2018-03-12 10:46                                               ` Johannes Schindelin
2018-03-13  0:16                                                 ` Igor Djordjevic
2018-03-26 13:07                                                   ` Johannes Schindelin
2018-03-27  5:51                                                     ` Sergey Organov
2018-03-27 13:49                                                       ` Johannes Schindelin
2018-03-28  5:57                                                         ` Sergey Organov
2018-03-30 13:41                                                           ` Johannes Schindelin
2018-03-30 16:36                                                             ` Sergey Organov
2018-03-28  5:57                                                         ` Sergey Organov
     [not found]                                                           ` <CA+P7+xoDQ2mzhxeZPFhaY+TaSoKkQm=5AtoduHH06-VggOJ2jg@mail.gmail.com>
2018-03-28 11:29                                                             ` Sergey Organov
     [not found]                                                               ` <CA+P7+xo19mHrWz9Fy-ifgCcVJM2xwzcLj7F2NvFe2LwGbaJiDQ@mail.gmail.com>
2018-03-29  5:53                                                                 ` Sergey Organov
2018-03-30 10:38                                                                   ` Johannes Schindelin
2018-03-30 12:36                                                                     ` Sergey Organov
2018-03-30 13:33                                                                       ` Johannes Schindelin
2018-03-30 15:13                                                                         ` Sergey Organov
2018-03-28 12:10                                                             ` Sergey Organov
2018-03-08 16:07                                         ` Jacob Keller
2018-03-11 12:11                                           ` Johannes Schindelin
2018-03-11 17:46                                             ` Igor Djordjevic
2018-03-08 15:16                                       ` Igor Djordjevic
2018-03-08 16:21                                         ` Igor Djordjevic
2018-03-11 12:22                                           ` Johannes Schindelin
2018-03-14 14:24                                         ` Sergey Organov
2018-03-14 23:11                                           ` Igor Djordjevic
2018-03-15  6:00                                             ` Sergey Organov
2018-03-15 21:51                                               ` Igor Djordjevic
2018-03-17  2:08                                             ` Igor Djordjevic
2018-03-19  5:44                                               ` Sergey Organov
2018-03-19 21:35                                                 ` Igor Djordjevic
2018-03-20 14:43                                                   ` Sergey Organov
2018-03-26 13:47                                           ` Johannes Schindelin
2018-03-06 23:24                                   ` Junio C Hamano
2018-03-07  7:09                                     ` Johannes Schindelin
2018-03-07 18:20                                       ` Junio C Hamano
2018-03-08  7:03                                         ` Johannes Schindelin
2018-03-08  8:11                                           ` Junio C Hamano
2018-03-09 17:09                                             ` Johannes Schindelin
2018-03-02 16:00                         ` Jacob Keller
2018-03-02 18:14                           ` Igor Djordjevic
2018-03-03 17:29                             ` Igor Djordjevic
2018-03-05  5:35                               ` Sergey Organov
2018-03-02 11:31                     ` [RFC] Rebasing merges: a jorney to the ultimate solution (Road Clear) Phillip Wood
2018-03-03  0:29                       ` Igor Djordjevic
2018-03-05  5:00                         ` Sergey Organov
2018-03-06 10:52                           ` Phillip Wood
2018-03-06 16:56                             ` Junio C Hamano
2018-03-08  7:05                               ` Johannes Schindelin
2018-03-08  8:18                                 ` Junio C Hamano
2018-03-11 11:56                                   ` Johannes Schindelin
2018-03-13 18:24                                     ` Junio C Hamano
2018-03-26 13:17                                       ` Johannes Schindelin
2018-03-05 17:29                         ` Johannes Schindelin
2018-03-06 23:21                           ` Igor Djordjevic
2018-03-07  7:04                             ` Johannes Schindelin
2018-03-06 10:45                         ` Phillip Wood
2018-03-06 11:45                           ` Sergey Organov
2018-03-08 16:30                             ` Igor Djordjevic
2018-03-06 18:12                           ` Johannes Schindelin
2018-03-07  5:08                             ` Sergey Organov
2018-03-07  6:58                               ` Johannes Schindelin
2018-03-07 14:34                                 ` Sergey Organov
2018-03-08  6:45                                   ` Johannes Schindelin
2018-03-12 12:31                                     ` Sergey Organov
2018-03-26 11:37                                       ` Johannes Schindelin
2018-03-27  5:11                                         ` Sergey Organov
2018-03-27 12:55                                           ` Johannes Schindelin
2018-03-28  4:32                                             ` Sergey Organov
2018-03-08 11:08                             ` Phillip Wood
2018-03-05 17:52                       ` Johannes Schindelin
2018-03-13 16:10                       ` Sergey Organov
2018-03-14  1:12                         ` Igor Djordjevic
2018-03-14  7:21                           ` Sergey Organov
2018-03-15  0:09                             ` Igor Djordjevic
2018-03-15  7:52                               ` Sergey Organov
2018-03-15 23:08                                 ` Igor Djordjevic
2018-03-16  7:31                                   ` Sergey Organov
2018-03-17  3:04                                     ` Igor Djordjevic
2018-03-19  6:01                                       ` Sergey Organov
2018-03-26 14:11                                   ` Johannes Schindelin
2018-02-28  0:29         ` Jacob Keller
2018-02-27 11:57     ` Sergey Organov
2018-02-27 18:14       ` Junio C Hamano
2018-02-28  0:30         ` Jacob Keller
2018-02-28  5:54           ` Sergey Organov
2018-02-28  4:53         ` Sergey Organov
2018-03-06 13:26 ` [RFC v2] " Sergey Organov
2018-03-07  6:46   ` Johannes Schindelin
2018-03-07 13:27     ` Sergey Organov
2018-03-07 14:08       ` Johannes Schindelin
2018-03-07 15:16         ` Sergey Organov
2018-03-08  7:01           ` Johannes Schindelin
2018-03-12 12:42             ` Sergey Organov
2018-03-26 11:50               ` Johannes Schindelin
2018-03-08 19:58         ` Igor Djordjevic
2018-03-08 20:27           ` Igor Djordjevic
2018-03-08 22:05             ` Igor Djordjevic
2018-03-08 23:31               ` Igor Djordjevic
2018-03-11 15:47                 ` Johannes Schindelin
2018-03-11 20:53                   ` Igor Djordjevic
2018-03-12 10:20                     ` Johannes Schindelin
2018-03-12 13:49                       ` Sergey Organov
2018-03-26 12:44                         ` Johannes Schindelin
2018-03-27  5:32                           ` Sergey Organov
2018-03-13  0:29                       ` Igor Djordjevic
2018-03-26 13:58                         ` Johannes Schindelin
2018-03-12 13:07                     ` Sergey Organov
2018-03-11 15:40           ` Johannes Schindelin
2018-03-11 22:04             ` Igor Djordjevic
2018-03-12 12:05               ` Sergey Organov
2018-03-26 11:33                 ` Johannes Schindelin
2018-03-27  5:34                   ` Sergey Organov
2018-03-12 22:41               ` Igor Djordjevic

Reply instructions:

You may reply publically 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1802272330290.56@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=igor.d.djordjevic@gmail.com \
    --cc=j6t@kdbg.org \
    --cc=jacob.keller@gmail.com \
    --cc=sorganov@gmail.com \
    /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

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox