{"thread":{"id":"47787","subject":"Unexpected git diff output during merge conflict","startedAt":"2018-02-08T10:52:18Z","lastAt":"2018-02-08T11:50:29Z","messageCount":3,"participants":["Nick O'Leary","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"338694","messageId":"CAF=vhqdJ2fByjSVt37b34wQUFo5_tb7rHbCddsaCzdvKywSBdg@mail.gmail.com","threadId":"47787","inReplyTo":null,"subject":"Unexpected git diff output during merge conflict","fromName":"Nick O'Leary","fromEmail":"nick.oleary@gmail.com","sentAt":"2018-02-08T10:51:57Z","receivedAt":"2018-02-08T10:52:18Z","isPatch":false,"sender":{"key":"nick.oleary@gmail.com","avatar":null},"body":"Hi,\n\nI have a merge conflict on a file and the git diff output looks wrong to me.\n\nHere's how to recreate:\n\nOn branch 'dev' add/commit a file (called README.md) with the contents\n( '------' used to delimit the file, not included in the content):\n\n-------\nThis is my default readme\n-------\n\n\nOn branch 'master' add/commit the same file with the contents:\n\n-------\nmerged-history-test\n===================\n\n### About\n\nThis is your project's README.md file. It helps users understand what your\nproject does, how to use it and anything else they may need to know.\n-------\n\n\nThen, whilst on master, run `git merge dev` and get the inevitable\nmerge conflict on this file.\n\nRunning `git diff README.md` gives:\n\n$ git diff README.md\ndiff --cc README.md\nindex 61d78b2,620d806..0000000\n--- a/README.md\n+++ b/README.md\n@@@ -1,7 -1,1 +1,11 @@@\n -This is my default readme\n++<<<<<<< HEAD\n +merged-history-test\n +===================\n +\n +### About\n +\n +This is your project's README.md file. It helps users understand what your\n- project does, how to use it and anything else they may need to know.\n++project does, how to use it and anything else they may need to know.\n++=======\n++This is my default readme\n++>>>>>>> dev\n\nThis does not look right to me. The 'This is my default readme' line\nhas ++ at the start - suggesting its new to both parent copies of the\nfile, which isn't the case - it came from the dev branch so should be\nprefixed with '+ '.\nI'm also not clear why the line beginning 'project does' has both a -\nand ++ prefix.\n\nIn every description of the Combined Diff format that I've been able\nto find, they only show having '+ ' or ' +' prefixes on the actual\ncontent and '++' on the <<<</=====/>>>> lines.\n\n\nAm I missing something here?\n\nThanks,\nNick\n"},{"id":"338696","messageId":"20180208112508.GA3506@sigill.intra.peff.net","threadId":"47787","inReplyTo":"CAF=vhqdJ2fByjSVt37b34wQUFo5_tb7rHbCddsaCzdvKywSBdg@mail.gmail.com","subject":"Re: Unexpected git diff output during merge conflict","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-02-08T11:25:08Z","receivedAt":"2018-02-08T11:25:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 08, 2018 at 10:51:57AM +0000, Nick O'Leary wrote:\n\n> $ git diff README.md\n> diff --cc README.md\n> index 61d78b2,620d806..0000000\n> --- a/README.md\n> +++ b/README.md\n> @@@ -1,7 -1,1 +1,11 @@@\n>  -This is my default readme\n> ++<<<<<<< HEAD\n>  +merged-history-test\n>  +===================\n>  +\n>  +### About\n>  +\n>  +This is your project's README.md file. It helps users understand what your\n> - project does, how to use it and anything else they may need to know.\n> ++project does, how to use it and anything else they may need to know.\n> ++=======\n> ++This is my default readme\n> ++>>>>>>> dev\n> \n> This does not look right to me. The 'This is my default readme' line\n> has ++ at the start - suggesting its new to both parent copies of the\n> file, which isn't the case - it came from the dev branch so should be\n> prefixed with '+ '.\n> I'm also not clear why the line beginning 'project does' has both a -\n> and ++ prefix.\n\nAre you sure there aren't whitespace differences in those two lines?\n\nFor instance, if I do:\n\n  # base commit\n  git init\n  git commit --allow-empty -m base\n\n  # one side; note missing newline!\n  printf 'this is my default readme' >file\n  git add file\n  git commit -m default\n\n  # other side\n  git checkout -b other HEAD^\n  {\n\techo this is a longer\n\techo and more involved\n\techo README\n  } >file\n  git add file\n  git commit -m longer\n\n  # and now merge and get a conflict\n  git merge master\n\nThen I get similar output to you.  The content with merge-conflicts\ncan't represent the original lack-of-newline for that file, because of\ncourse there's another \">>>\" line after it.\n\nIf I swap out the printf for echo, adding the newline, then it produces\nthe output you'd expect.\n\n-Peff\n"},{"id":"338698","messageId":"CAF=vhqdq47sb6wH7PEUif5ZjGJzKaO7fW-hbHVz3c=vp2AMBMg@mail.gmail.com","threadId":"47787","inReplyTo":"20180208112508.GA3506@sigill.intra.peff.net","subject":"Re: Unexpected git diff output during merge conflict","fromName":"Nick O'Leary","fromEmail":"nick.oleary@gmail.com","sentAt":"2018-02-08T11:50:08Z","receivedAt":"2018-02-08T11:50:29Z","isPatch":false,"sender":{"key":"nick.oleary@gmail.com","avatar":null},"body":"Ah, the whitespace that was added to enable the >>> markers to be\nadded... that makes sense.\n\nWhich means the output is correct and some assumptions my code makes\nabout the format of the Combined Diff are wrong.\n\nThanks!\nNick\n\n\n\nOn 8 February 2018 at 11:25, Jeff King <peff@peff.net> wrote:\n> On Thu, Feb 08, 2018 at 10:51:57AM +0000, Nick O'Leary wrote:\n>\n>> $ git diff README.md\n>> diff --cc README.md\n>> index 61d78b2,620d806..0000000\n>> --- a/README.md\n>> +++ b/README.md\n>> @@@ -1,7 -1,1 +1,11 @@@\n>>  -This is my default readme\n>> ++<<<<<<< HEAD\n>>  +merged-history-test\n>>  +===================\n>>  +\n>>  +### About\n>>  +\n>>  +This is your project's README.md file. It helps users understand what your\n>> - project does, how to use it and anything else they may need to know.\n>> ++project does, how to use it and anything else they may need to know.\n>> ++=======\n>> ++This is my default readme\n>> ++>>>>>>> dev\n>>\n>> This does not look right to me. The 'This is my default readme' line\n>> has ++ at the start - suggesting its new to both parent copies of the\n>> file, which isn't the case - it came from the dev branch so should be\n>> prefixed with '+ '.\n>> I'm also not clear why the line beginning 'project does' has both a -\n>> and ++ prefix.\n>\n> Are you sure there aren't whitespace differences in those two lines?\n>\n> For instance, if I do:\n>\n>   # base commit\n>   git init\n>   git commit --allow-empty -m base\n>\n>   # one side; note missing newline!\n>   printf 'this is my default readme' >file\n>   git add file\n>   git commit -m default\n>\n>   # other side\n>   git checkout -b other HEAD^\n>   {\n>         echo this is a longer\n>         echo and more involved\n>         echo README\n>   } >file\n>   git add file\n>   git commit -m longer\n>\n>   # and now merge and get a conflict\n>   git merge master\n>\n> Then I get similar output to you.  The content with merge-conflicts\n> can't represent the original lack-of-newline for that file, because of\n> course there's another \">>>\" line after it.\n>\n> If I swap out the printf for echo, adding the newline, then it produces\n> the output you'd expect.\n>\n> -Peff\n"}]}