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

Re: BUG: CR marker ^M doesn't show up in '-' lines of diffs when the ending of the removed line is CR+LF

From
Johannes Sixt <j6t@kdbg.org>
Date
Nov 23, 2018, 21:47 UTC
Message-ID
<4dca3f64-4851-6d48-8266-dfe55f597739@kdbg.org>
In-Reply-To
<1f068f3a-d636-9b9c-f501-51d33412b964@googlemail.com>
Am 23.11.18 um 19:19 schrieb Frank Schäfer:
Show 5 quoted lines
> The CR marker ^M doesn't show up in '-' lines of diffs when the ending
> of the removed line is CR+LF.
> It shows up as expected in '-' lines when the ending of the removed line
> is CR only.
> It also always shows up as expected in '+' lines.

Is your repository configured to (1) highlight whitespace errors in diff output and (2) to leave CRLF alone in text files?

If so, then it is just a side-effect of this combination, an illusion, so to say: The CR in the CRLF combo is trailing whitespace. The 'git diff' marks it by inserting an escape sequence to switch the color before ^M and another escape sequence to reset to color after ^M. This breaks the CRLF combination apart, so that the pager does not process it as a combined CRLF sequence; it displays the lone CR as ^M.

It is easy to achieve the opposite effect, i.e., that ^M is not displayed. For example with these lines in .git/info/attributes or .gitattributes:

*.cpp whitespace=trailing-space,cr-at-eol,indent-with-non-tab,space-before-tab *.h whitespace=trailing-space,cr-at-eol,indent-with-non-tab,space-before-tab

Note the cr-at-eol. (There may be shorter versions to achieve a similar effect.)

-- Hannes
Previous: Frank SchäferNext: Frank Schäfer
Message 2 of 23 in “BUG: CR marker ^M doesn't show up in '-' lines of diffs when the ending of the removed line is CR+LF”
  1. Frank SchäferNov 23, 2018
  2. Johannes SixtNov 23, 2018
  3. Frank SchäferNov 24, 2018
  4. Torsten BögershausenNov 24, 2018
  5. Johannes SixtNov 24, 2018
  6. Frank SchäferNov 25, 2018
  7. Johannes SixtNov 25, 2018
  8. Junio C HamanoNov 26, 2018
  9. brian m. carlsonNov 25, 2018
  10. Johannes SixtNov 26, 2018
  11. Junio C HamanoNov 26, 2018
  12. Johannes SixtNov 27, 2018
  13. Frank SchäferNov 27, 2018
  14. Junio C HamanoNov 29, 2018
  15. Frank SchäferDec 2, 2018
  16. Johannes SixtDec 2, 2018
  17. Frank SchäferDec 5, 2018
  18. Johannes SixtDec 5, 2018
  19. Junio C HamanoDec 3, 2018
  20. Frank SchäferDec 5, 2018
  21. Junio C HamanoDec 6, 2018
  22. Frank SchäferDec 6, 2018
  23. Frank SchäferNov 27, 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.