* Unexpected git diff output during merge conflict
@ 2018-02-08 10:51 Nick O'Leary
2018-02-08 11:25 ` Jeff King
0 siblings, 1 reply; 3+ messages in thread
From: Nick O'Leary @ 2018-02-08 10:51 UTC (permalink / raw)
To: git
Hi,
I have a merge conflict on a file and the git diff output looks wrong to me.
Here's how to recreate:
On branch 'dev' add/commit a file (called README.md) with the contents
( '------' used to delimit the file, not included in the content):
-------
This is my default readme
-------
On branch 'master' add/commit the same file with the contents:
-------
merged-history-test
===================
### About
This is your project's README.md file. It helps users understand what your
project does, how to use it and anything else they may need to know.
-------
Then, whilst on master, run `git merge dev` and get the inevitable
merge conflict on this file.
Running `git diff README.md` gives:
$ git diff README.md
diff --cc README.md
index 61d78b2,620d806..0000000
--- a/README.md
+++ b/README.md
@@@ -1,7 -1,1 +1,11 @@@
-This is my default readme
++<<<<<<< HEAD
+merged-history-test
+===================
+
+### About
+
+This is your project's README.md file. It helps users understand what your
- project does, how to use it and anything else they may need to know.
++project does, how to use it and anything else they may need to know.
++=======
++This is my default readme
++>>>>>>> dev
This does not look right to me. The 'This is my default readme' line
has ++ at the start - suggesting its new to both parent copies of the
file, which isn't the case - it came from the dev branch so should be
prefixed with '+ '.
I'm also not clear why the line beginning 'project does' has both a -
and ++ prefix.
In every description of the Combined Diff format that I've been able
to find, they only show having '+ ' or ' +' prefixes on the actual
content and '++' on the <<<</=====/>>>> lines.
Am I missing something here?
Thanks,
Nick
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Unexpected git diff output during merge conflict
2018-02-08 10:51 Unexpected git diff output during merge conflict Nick O'Leary
@ 2018-02-08 11:25 ` Jeff King
2018-02-08 11:50 ` Nick O'Leary
0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2018-02-08 11:25 UTC (permalink / raw)
To: Nick O'Leary; +Cc: git
On Thu, Feb 08, 2018 at 10:51:57AM +0000, Nick O'Leary wrote:
> $ git diff README.md
> diff --cc README.md
> index 61d78b2,620d806..0000000
> --- a/README.md
> +++ b/README.md
> @@@ -1,7 -1,1 +1,11 @@@
> -This is my default readme
> ++<<<<<<< HEAD
> +merged-history-test
> +===================
> +
> +### About
> +
> +This is your project's README.md file. It helps users understand what your
> - project does, how to use it and anything else they may need to know.
> ++project does, how to use it and anything else they may need to know.
> ++=======
> ++This is my default readme
> ++>>>>>>> dev
>
> This does not look right to me. The 'This is my default readme' line
> has ++ at the start - suggesting its new to both parent copies of the
> file, which isn't the case - it came from the dev branch so should be
> prefixed with '+ '.
> I'm also not clear why the line beginning 'project does' has both a -
> and ++ prefix.
Are you sure there aren't whitespace differences in those two lines?
For instance, if I do:
# base commit
git init
git commit --allow-empty -m base
# one side; note missing newline!
printf 'this is my default readme' >file
git add file
git commit -m default
# other side
git checkout -b other HEAD^
{
echo this is a longer
echo and more involved
echo README
} >file
git add file
git commit -m longer
# and now merge and get a conflict
git merge master
Then I get similar output to you. The content with merge-conflicts
can't represent the original lack-of-newline for that file, because of
course there's another ">>>" line after it.
If I swap out the printf for echo, adding the newline, then it produces
the output you'd expect.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Unexpected git diff output during merge conflict
2018-02-08 11:25 ` Jeff King
@ 2018-02-08 11:50 ` Nick O'Leary
0 siblings, 0 replies; 3+ messages in thread
From: Nick O'Leary @ 2018-02-08 11:50 UTC (permalink / raw)
To: Jeff King; +Cc: git
Ah, the whitespace that was added to enable the >>> markers to be
added... that makes sense.
Which means the output is correct and some assumptions my code makes
about the format of the Combined Diff are wrong.
Thanks!
Nick
On 8 February 2018 at 11:25, Jeff King <peff@peff.net> wrote:
> On Thu, Feb 08, 2018 at 10:51:57AM +0000, Nick O'Leary wrote:
>
>> $ git diff README.md
>> diff --cc README.md
>> index 61d78b2,620d806..0000000
>> --- a/README.md
>> +++ b/README.md
>> @@@ -1,7 -1,1 +1,11 @@@
>> -This is my default readme
>> ++<<<<<<< HEAD
>> +merged-history-test
>> +===================
>> +
>> +### About
>> +
>> +This is your project's README.md file. It helps users understand what your
>> - project does, how to use it and anything else they may need to know.
>> ++project does, how to use it and anything else they may need to know.
>> ++=======
>> ++This is my default readme
>> ++>>>>>>> dev
>>
>> This does not look right to me. The 'This is my default readme' line
>> has ++ at the start - suggesting its new to both parent copies of the
>> file, which isn't the case - it came from the dev branch so should be
>> prefixed with '+ '.
>> I'm also not clear why the line beginning 'project does' has both a -
>> and ++ prefix.
>
> Are you sure there aren't whitespace differences in those two lines?
>
> For instance, if I do:
>
> # base commit
> git init
> git commit --allow-empty -m base
>
> # one side; note missing newline!
> printf 'this is my default readme' >file
> git add file
> git commit -m default
>
> # other side
> git checkout -b other HEAD^
> {
> echo this is a longer
> echo and more involved
> echo README
> } >file
> git add file
> git commit -m longer
>
> # and now merge and get a conflict
> git merge master
>
> Then I get similar output to you. The content with merge-conflicts
> can't represent the original lack-of-newline for that file, because of
> course there's another ">>>" line after it.
>
> If I swap out the printf for echo, adding the newline, then it produces
> the output you'd expect.
>
> -Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-08 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-08 10:51 Unexpected git diff output during merge conflict Nick O'Leary
2018-02-08 11:25 ` Jeff King
2018-02-08 11:50 ` Nick O'Leary
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).