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