git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Unexpected git diff output during merge conflict

From
Jeff King <peff@peff.net>
Date
Feb 8, 2018, 11:25 UTC
Message-ID
<20180208112508.GA3506@sigill.intra.peff.net>
In-Reply-To
<CAF=vhqdJ2fByjSVt37b34wQUFo5_tb7rHbCddsaCzdvKywSBdg@mail.gmail.com>
On Thu, Feb 08, 2018 at 10:51:57AM +0000, Nick O'Leary wrote:
Show 26 quoted lines
> $ 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
Previous: Nick O'LearyNext: Nick O'Leary
Message 2 of 3 in “Unexpected git diff output during merge conflict”
  1. Nick O'LearyFeb 8, 2018
  2. Jeff KingFeb 8, 2018
  3. Nick O'LearyFeb 8, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.