git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: "Hrvoje Nikšić" <hniksic@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Converting merge to rebase in the presence of conflicts
Date: Tue, 12 Apr 2011 04:55:22 +0200	[thread overview]
Message-ID: <4DA3BF1A.7030407@alum.mit.edu> (raw)
In-Reply-To: <BANLkTinVUdmG56oPQXvMhFh6hLcFj3_jZg@mail.gmail.com>

On 04/11/2011 05:15 PM, Hrvoje Nikšić wrote:
> [...]
> I still wonder why rerere is necessary here. After all, even without
> the rerere metadata, the information about conflict resolution is
> right there, in the merge commit, and rebase could conceivably make
> use of it. What am I missing?

In general, merge and rebase are quite different animals.  In the
example you provided, there was only one conflicting commit being
rebased, so the difference is not so apparent.

One commit merged:

*--*--a--m      "master"
    \   /
     b--

One commit rebased:

*--*--a                           *--*--a--b'        "master"
    \              ->
     b

In either case, "git diff a..master" is identical.  Therefore,
converting "one commit merged" into "one commit rebased" simply involves
forgetting the second parent of commit "m".  The "rerere" facility will
indeed help you here, as other people have suggested.

But if more than one commit is being brought in from the branch, then
merge and rebase are more distinct.  Merge forces you to resolve the
conflicts only once, in a single merge commit, whereas rebase forces you
to resolve the conflicts one commit at a time.

Multiple commits merged:

*--*--a---M      "master"
    \    /
     b--c

Multiple commits rebased:

*--*--a                          *--*--a--b'--c'     "master"
    \              ->
     b--c

It should still be that "git diff a..master" gives identical results in
the two cases, but there is still a big difference--in the rebase
example, master after commit "b'" should be a functional state that can
be compiled and passes the unit tests.  The state at commit "b'"
includes a combination of the changes made in "a" plus the changes made
in the original "b".  In the merge example, there is no state of the
tree that is equivalent; there is only a+b+c.  This lack of intermediate
conflict resolution is what makes merges problematic for "git bisect".

Now, you want a way to transform the merge into a rebase automatically.
 In other words, given the information in the "multiple commits merged"
example as raw material, how can you convert it into a rebase?  This is
only possible if you are willing to squash "b", "c", and "M" into a
single commit:

*--*--a--bcM

because you have only told git how to resolve the conflicts between "a"
and "b+c", not between "a" and "b" without "c".

This is why I have advocated "rebase with history" [1], which retains
both the intermediate conflict resolutions and also the merge information:

*--*--a--b'--c'     "master"
    \   /   /
     --b---c

Michael

[1]
http://softwareswirl.blogspot.com/2009/04/truce-in-merge-vs-rebase-war.html

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

  reply	other threads:[~2011-04-12  2:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 14:13 Converting merge to rebase in the presence of conflicts Hrvoje Nikšić
2011-04-11 14:39 ` Michael J Gruber
2011-04-11 15:03 ` Johannes Sixt
2011-04-11 15:15   ` Hrvoje Nikšić
2011-04-12  2:55     ` Michael Haggerty [this message]
2011-04-12  6:11     ` 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

  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=4DA3BF1A.7030407@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=hniksic@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).