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

Re: [BUG] `git diff` treats an unchanged line as modified

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 24, 2019, 19:34 UTC
Message-ID
<xmqqy2v14iwc.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CA+PpKPm0_zXr978Mw8h7owHBChx-uqVCdjrtuh45uOS-A_0qrA@mail.gmail.com>
Hao Lee <haolee.swjtu@gmail.com> writes:
> I think the latter is correct because the fifth line is not changed
> and it's still a line which only contains a whitespace.

As long as lines that begin with "-" and " " match what the 'old' file has, and replacing them with lines that begin with " " and "+" in the 'old' file yields the 'new' file, any patch is "correct".

IOW, there is no *single* diff output that is correct.

Among many "correct" diff output, there are ones that readers find them easier to understand and those that look suboptimal. The differences are often personal tastes.

"git diff" has options to tweak heuristics it uses to choose among many "correct" diff outputs, like --patience, --histogram, etc. Perhaps using one of them would produce one that match your taste better?

Previous: Hao LeeNext: Hao Lee
Message 2 of 3 in “[BUG] `git diff` treats an unchanged line as modified”
  1. Hao LeeDec 24, 2019
  2. Junio C HamanoDec 24, 2019
  3. Hao LeeDec 25, 2019

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.