{"thread":{"id":"15900","subject":"Problem with CRLF line endings and colored diff","startedAt":"2008-10-14T21:13:59Z","lastAt":"2008-10-14T23:08:17Z","messageCount":3,"participants":["Jean-Luc Herren","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"93031","messageId":"48F50B97.9090106@gmx.ch","threadId":"15900","inReplyTo":null,"subject":"Problem with CRLF line endings and colored diff","fromName":"Jean-Luc Herren","fromEmail":"jlh@gmx.ch","sentAt":"2008-10-14T21:13:59Z","receivedAt":"2008-10-14T21:13:59Z","isPatch":false,"sender":{"key":"jlh@gmx.ch","avatar":null},"body":"Hello list!\n\nI'm using CRLF line endings on the files of a project and I'm\nrunning into odd output from 'git diff'.  Here are the steps to\nreproduce:\n\n    git init\n    echo -e 'line1\\r' > file\n    git add file\n    echo -e 'line2\\r' > file\n    PAGER='less -R' git diff --color\n\nThe output looks like this:\n\n    diff --git a/file b/file\n    index 495181c..a1413a4 100644\n    --- a/file\n    +++ b/file\n    @@ -1 +1 @@\n    -line1\n    +line2^M\n\nNote the trailing ^M on the '+' line.  After examining that line\nit seems it's a bug in git, as that line really looks like this\n(<...> denoting ANSI sequences or CR/LF):\n\n    <GREEN FOREGROUND>+<RESET><GREEN FOREGROUND>\n    line2<RESET><RED BACKGROUND><CR><RESET><LF>\n\nThe CR and the LF are not after each other, there's an ANSI\nsequence in between (because the CR is being highlighted as white\nspace).  That confuses 'less'.  The '-' line above does not do\nthat and thus doesn't have this problem.  It also doesn't reset\nthe color between the '-' and the line:\n\n    <RED FOREGROUND>-line1<RESET><CR><LF>\n\nI tried poking around the code, but the diff machinery is more\ncomplex than could be quickly grasped, so I'll let someone that\nknows it already have a look.\n\nUsing git 1.6.0.2, but have the same problem with HEAD.\n\njlh\n"},{"id":"93038","messageId":"7v4p3e7r9e.fsf@gitster.siamese.dyndns.org","threadId":"15900","inReplyTo":"48F50B97.9090106@gmx.ch","subject":"Re: Problem with CRLF line endings and colored diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-14T22:20:45Z","receivedAt":"2008-10-14T22:20:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jean-Luc Herren <jlh@gmx.ch> writes:\n\n>     <GREEN FOREGROUND>+<RESET><GREEN FOREGROUND>\n>     line2<RESET><RED BACKGROUND><CR><RESET><LF>\n\nThis is expected and deliberate, as you haven't told about your desire to\nconsider carriage-returns not as line termination letter.  By default CR\nis just one of the whitespace letters, and colored diff output is\nreminding you that you introduced a line with a trailing whitespace.\n\nCheck git-config(1) and look for \"core.whitespace\", paying special\nattention to \"cr-at-eol\".\n"},{"id":"93043","messageId":"48F52661.4010800@gmx.ch","threadId":"15900","inReplyTo":"7v4p3e7r9e.fsf@gitster.siamese.dyndns.org","subject":"Re: Problem with CRLF line endings and colored diff","fromName":"Jean-Luc Herren","fromEmail":"jlh@gmx.ch","sentAt":"2008-10-14T23:08:17Z","receivedAt":"2008-10-14T23:08:17Z","isPatch":false,"sender":{"key":"jlh@gmx.ch","avatar":null},"body":"Junio C Hamano wrote:\n> Jean-Luc Herren <jlh@gmx.ch> writes:\n>>     <GREEN FOREGROUND>+<RESET><GREEN FOREGROUND>\n>>     line2<RESET><RED BACKGROUND><CR><RESET><LF>\n> \n> This is expected and deliberate, as you haven't told about your desire to\n> consider carriage-returns not as line termination letter.  By default CR\n> is just one of the whitespace letters, and colored diff output is\n> reminding you that you introduced a line with a trailing whitespace.\n\nAh, I see, I didn't know I have to tell it that I want to use\nCRLF...  Works fine now.  Sorry for the noise.\n\njlh\n"}]}