git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Nahas <mike.nahas@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Jakub Narebski <jnareb@gmail.com>,
	Michael J Gruber <git@drmicha.warpmail.net>,
	Junio C Hamano <gitster@pobox.com>,
	Scott Chacon <schacon@gmail.com>,
	git@vger.kernel.org
Subject: Re: Command-line interface thoughts (ad-hominem attacks)
Date: Wed, 8 Jun 2011 21:56:08 -0400	[thread overview]
Message-ID: <BANLkTikamzsiSJqkRjA7nDjRoyEbd32rvw@mail.gmail.com> (raw)
In-Reply-To: <20110609004347.GC19715@sigill.intra.peff.net>

Hi Peff,

First, thanks for correcting my diff-without-NEXT-and-WTREE to
diff-with-NEXT-and-WTREE pairing.

Second, I agree that the index is more than just NEXT.  There were
good reasons behind calling it "NEXT" and not "INDEX".

Third, I didn't know for sure that "git diff" during a merge conflict
would produce a three-way-diff result, but I suspected it would.  (You
really didn't have to produce all that code - I would have accepted
your word as an expert.  But thanks!)  So, yes, the two-way merge
result of "git diff NEXT WTREE" would be different.

I could argue that git should allow a 4-way diff where "git diff NEXT
WTREE OURS THEIR" prints all the unresolved changes as coming from
OURS or THEIR or neither.  But I think that's silly.

I will say that "git diff NEXT WTREE" will tell you what's left
unresolved and most of it is in <<<<====>>>>> blocks that tell you
whether it came from OURS or THEIRS.  If the user has any discipline,
they won't introduce unnecessary changes that were not necessary for
the merge.  If they don't have discipline, we really can't help them.

I'm not saying there is no use for a 3-way merge.  In fact, I'd guess
it's a requirement so that Alice can check Bob's merge before Bob
commits.  But I'm fine with making it "git diff --3-way" or the silly
"git diff NEXT WTREE OURS THEIRS" because I think its "git diff NEXT
WTREE" will be good enough 99% of the time.



On Wed, Jun 8, 2011 at 8:43 PM, Jeff King <peff@peff.net> wrote:
> On Wed, Jun 08, 2011 at 02:57:09PM -0400, Michael Nahas wrote:
>
>> > Isn't this going to be behavior change, since your NEXT is not quite the
>> > same as the index? How do I now get an n-way combined diff of the
>> > unmerged files in the index?
>>
>> The index is a file in .git/ that serves many purposes.  NEXT is an
>> image of the whole project.  NEXT can be computed from the index and
>> HEAD.
>>
>> During a conflicted merge, stage 0 of the index holds the resolved
>> files.  WTREE holds all merge files: the resolved and the unresolved
>> (which have <<<< ==== >>>> blocks in them).  I propose that during a
>> conflicted merge, that NEXT be computed as HEAD plus the resolved
>> files, that is, the files in stage 0 of the index.
>
> OK. So NEXT actually has less information than the whole index, because
> it doesn't contain information on what was on either side of the merge
> originally (or in the merge base).
>
>> "git diff HEAD NEXT" would print the resolved changes.
>> "git diff NEXT WTREE" would print the unresolved changes
>> "git diff HEAD WTREE" would print all changes.
>>
>> I believe that is the same behaviour as "git diff", "git diff
>> --cached" and "git diff HEAD" during a conflicted merge.
>
> I assume you don't mean respectively here, but rather:
>
>  git diff          => git diff NEXT WTREE
>  git diff --cached => git diff HEAD NEXT
>  git diff HEAD     => git diff HEAD WTREE
>
> But even still, I don't think "git diff" is the same. Try this:
>
>  git init repo && cd repo
>  echo one >file && git add file && git commit -m one &&
>  echo two >file && git add file && git commit -m two &&
>  git checkout -b other HEAD^ &&
>  echo three >file && git add file && git commit -m three &&
>  ! git merge master &&
>  git diff
>
> I get:
>
>  diff --cc file
>  index 2bdf67a,f719efd..0000000
>  --- a/file
>  +++ b/file
>  @@@ -1,1 -1,1 +1,5 @@@
>  ++<<<<<<< HEAD
>   +three
>  ++=======
>  + two
>  ++>>>>>>> master
>
> Note that this is _not_ a diff between NEXT and the working tree.  It is a
> 3-way "combined" diff of what's in the working tree compared to each side of
> the merge.
>
> If NEXT is a tree that contains HEAD plus stage 0 files, then we would
> see a 2-way diff of the HEAD version of "file" and the working tree
> version. I.e., the same as "git diff HEAD -- file":
>
>  diff --git a/file b/file
>  index 2bdf67a..087e97e 100644
>  --- a/file
>  +++ b/file
>  @@ -1 +1,5 @@
>  +<<<<<<< HEAD
>   three
>  +=======
>  +two
>  +>>>>>>> master
>
> which looks similar, because we haven't started resolving anything yet.
> But try resolving it like this:
>
>  cat >file <<'EOF'
>  three
>  and
>  two
>  EOF
>
> Now try "git diff" again. You should get:
>
>  diff --cc file
>  index 2bdf67a,f719efd..0000000
>  --- a/file
>  +++ b/file
>  @@@ -1,1 -1,1 +1,3 @@@
>   +three
>  ++and
>  + two
>
> This shows us that "three" came from one side of the merge, "two" from
> the other, and that "and" was found in neither side.
>
> Compare to the 2-way that shows:
>
>  diff --git a/file b/file
>  index 2bdf67a..1ecff7e 100644
>  --- a/file
>  +++ b/file
>  @@ -1 +1,3 @@
>   three
>  +and
>  +two
>
> There's nothing to distinguish added code pulled from the other side of
> the merge versus changes that were made as part of the resolution.
>
> I think this is what Junio was talking about when he said that the index
> is more than a tree. There may be times when you want to treat the items
> in stage 0 as a tree, but diffing against the index is more than just
> diffing against that tree.
>
>> I do not know how "n-way" merge works.  I saw somewhere that indicated
>> that it was a series of N-1 two-way merges.
>
> Git history can represent a merge of any number of branches (an "octopus
> merge"), because the commits store only the final state and a list of
> parent commits. The combined diff format is capable of handling an
> arbitrary number of parents.
>
> I should have just said "3-way", though, because it's not relevant here.
> The index only has 2 stage bits, so we can only represent four stages
> ("resolved", "base", "ours", and "theirs"). So you can't represent an
> n-way merge in the index.
>
> So "git merge" just punts on an octopus merge if there are actual merge
> conflicts that would need to go in the index. So in practice, people
> just tend to do N-1 pair-wise merges.
>
> You can see some example octopus merges (and their combined diff) if you
> have a recent git (that supports --min-parents) with:
>
>  git log --min-parents=3 -p --cc
>
> in both git.git and linux-2.6.git.
>
> -Peff
>

  reply	other threads:[~2011-06-09  1:56 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BANLkTikTWx7A64vN+hVZgL7cuiZ16Eobgg@mail.gmail.com>
2011-06-04 16:17 ` Command-line interface thoughts Michael Nahas
2011-06-04 21:49   ` Jakub Narebski
2011-06-05  1:00     ` Michael Nahas
2011-06-05 11:10       ` Jakub Narebski
2011-06-05 18:39         ` Scott Chacon
2011-06-05 23:37           ` Jakub Narebski
2011-06-06  6:16           ` Junio C Hamano
2011-06-06  7:34             ` Michael J Gruber
2011-06-06 11:45               ` Michael Nahas
2011-06-06 12:19               ` Jakub Narebski
2011-06-06 13:20                 ` Michael J Gruber
2011-06-08 13:10                   ` Jakub Narebski
2011-06-06 16:23                 ` Junio C Hamano
2011-06-06 16:40                   ` Drew Northup
2011-06-06 14:00               ` Junio C Hamano
2011-06-06 14:16                 ` Michael J Gruber
2011-06-06 16:14                   ` Junio C Hamano
2011-06-06 17:42                     ` Scott Chacon
2011-06-06 19:01                       ` Junio C Hamano
     [not found]                         ` <BANLkTi=yytzDrJLvVn_ZhJOiQs-rqvKi1w@mail.gmail.com>
2011-06-07  2:31                           ` Michael Nahas
2011-06-07  4:03                             ` Junio C Hamano
2011-06-07 11:04                               ` Michael Nahas
2011-06-07  6:11                     ` Michael J Gruber
2011-06-07 11:45                       ` Jonathan Nieder
2011-06-07 19:00                         ` Holger Hellmuth
2011-06-07 19:11                           ` Jonathan Nieder
2011-06-07 20:33                             ` Jakub Narebski
2011-06-08 13:04                               ` Holger Hellmuth
2011-06-08 18:56                                 ` Jakub Narebski
2011-06-09 11:55                                   ` Holger Hellmuth
2011-06-10 16:44                                     ` Jakub Narebski
2011-06-10 18:07                                       ` Holger Hellmuth
2011-06-10 18:35                                         ` Jakub Narebski
2011-06-10 22:45                                           ` Holger Hellmuth
2011-06-13  3:43                                             ` git diff --added (Re: Command-line interface thoughts) Jonathan Nieder
2011-06-13  4:11                                               ` Miles Bader
2011-06-13  4:46                                                 ` Miles Bader
2011-06-13  8:06                                                 ` Jonathan Nieder
2011-06-13 12:55                                                   ` Junio C Hamano
2011-06-13 12:28                                                 ` Junio C Hamano
2011-06-13 19:47                                                   ` Holger Hellmuth
2011-06-13 20:31                                                     ` Michael Nahas
2011-06-13 10:15                                             ` Command-line interface thoughts Jakub Narebski
2011-06-13 22:33                                               ` Holger Hellmuth
2011-06-14  4:21                                               ` Michael Haggerty
2011-06-14  7:51                                                 ` Jakub Narebski
2011-06-07 19:34                         ` René Scharfe
2011-06-07 19:38                           ` Jakub Narebski
2011-06-08 11:12                       ` Command-line interface thoughts (ad-hominem attacks) Jakub Narebski
2011-06-08 11:39                         ` Michael Nahas
2011-06-08 12:42                           ` Jakub Narebski
2011-06-08 14:15                             ` Michael Nahas
2011-06-08 15:05                           ` Jeff King
2011-06-08 18:57                             ` Michael Nahas
2011-06-09  0:43                               ` Jeff King
2011-06-09  1:56                                 ` Michael Nahas [this message]
2011-06-10 15:29                                   ` Jakub Narebski
2011-06-09  9:48                               ` Command-line interface thoughts Jakub Narebski
2011-06-09 11:44                                 ` Michael Nahas
2011-06-09 12:45                                   ` Jakub Narebski
2011-06-09 13:06                                     ` Jakub Narebski
2011-06-09  9:06             ` Michael Haggerty
2011-06-09 10:02               ` Andreas Ericsson
2011-06-09 13:30                 ` Thomas Rast
2011-06-09 16:18               ` Jeff King
2011-06-09 17:15                 ` Jay Soffian
2011-06-09 17:20                   ` Jeff King
2011-06-09 17:36                   ` Junio C Hamano
2011-06-09 18:20                     ` Jay Soffian
2011-06-09 19:40                       ` Junio C Hamano
2011-06-09 18:03                 ` Michael Haggerty
2011-06-09 18:38                   ` Junio C Hamano
2011-06-09 19:17                     ` Michael Haggerty
2011-06-09 20:04                     ` Jeff King
2011-06-09 21:37                       ` Michael Haggerty
2011-06-09 22:04                         ` Jakub Narebski
2011-06-09 23:02                           ` Michael Haggerty
2011-06-10 10:19                             ` Jakub Narebski
2011-06-10 11:06                               ` Michael Nahas
2011-06-10 12:20                                 ` Jakub Narebski
2011-06-09 22:21                         ` Jeff King
2011-06-09 22:27                         ` Michael Nahas
2011-06-09 22:38                           ` Jeff King
2011-06-09 22:55                             ` Jakub Narebski
2011-06-10  0:00                             ` Michael Nahas
2011-06-10  0:08                               ` Jeff King
2011-06-10 21:48                       ` Junio C Hamano
2011-06-10 22:08                         ` Junio C Hamano
2011-06-10 23:05                         ` Jakub Narebski
2011-06-12  6:06                         ` Michael Haggerty
2011-06-12 21:12                           ` Junio C Hamano
2011-06-12 13:30                         ` Michael Nahas
2011-06-12 21:29                           ` Junio C Hamano
2011-06-13  2:14                             ` Michael Nahas
2011-06-13 18:50                         ` Jeff King
2011-06-09 19:41                   ` Jeff King
2011-06-05 21:22         ` Paul Ebermann
2011-06-05 21:34   ` Paul Ebermann

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=BANLkTikamzsiSJqkRjA7nDjRoyEbd32rvw@mail.gmail.com \
    --to=mike.nahas@gmail.com \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=mike@nahas.com \
    --cc=peff@peff.net \
    --cc=schacon@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.
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 NNTP newsgroup(s).