4

To hide the awful ^M characters from git diff, one has to config:

[core]
    whitespace = cr-at-eol

But they are still displayed in git grep output. How to solve that?

EDIT -- The grep I'm running is:

git grep -i --line-number --break --heading -C 1 <PATTERN>

in Cygwin (on Windows) with less -R as pager.

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
user3341592
  • 1,419
  • 1
  • 17
  • 36

1 Answers1

4

Quoting this from a similar question (which is related to git diff),

Change the core.pager to "tr -d '\r' | less -REX"

You can either change this configuration globally like this,

git config --global core.pager "tr -d '\r' | less -REX"

or just use it once for git grep,

git -c core.pager="tr -d '\r' | less -REX" grep -i --line-number --break --heading -C 1 <PATTERN>

User Jason Pyeron provides a thorough explanation here.

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • Crazy to do that, IMHO, while there is a setting for the diff… not followed for the grep part… but that works, thanks! – user3341592 Dec 18 '19 at 08:53
  • Would appreciate if you could address the side question as well - though you've already addressed, and resolved, the initial one! – user3341592 Dec 18 '19 at 08:55
  • And do you know which color is used for highlighting those accents? – user3341592 Dec 18 '19 at 09:42
  • @user3341592, can you provide more details ? what terminal you are using? what is the command being executed ? (`less` displays the non-ASCII characters correctly for me), it would be better if you could open a new question – Saurabh P Bhandari Dec 18 '19 at 17:08
  • OK. See https://stackoverflow.com/questions/59398963/could-git-correctly-display-iso-latin-1-accents-in-a-utf-8-terminal. Thanks! – user3341592 Dec 18 '19 at 19:35