Home > Enterprise >  git diff: What is red text background in terminal output?
git diff: What is red text background in terminal output?

Time:03-14

Here's the output of my terminal when I run a git diff and scroll down with down arrow. From what I can assume and a couple articles I found, it looks like the red highlighting represents a syntax error? Here's one source I found with good answers. git diff terminal zsh output with red text background

CodePudding user response:

The highlighted spaces indicate what git considers a whitespace error. git diff's --check option has some documentation on it:

       --check
           <...>
           By default, trailing whitespaces (including lines that consist solely of
           whitespaces) and a space character that is immediately followed by a tab
           character inside the initial indent of the line are considered
           whitespace errors.
           <...>

You can get the reason (which, in your case, will be "trailing whitespace") with git diff --check:

$ git diff --check
my_file:107: trailing whitespace.
 end        

CodePudding user response:

git diff can flag "whitespace errors". A whitespace error is what you pick, out of Git's set of possible configurations: use the core.whitespace configuration knob to set this. The default, as described in the git config documentation, is:

blank-at-eol,space-before-tab,blank-at-eof

Having detected a whitespace error, Git will flag this with the color setting, which defaults to this background-red that you see.

These are all configurable: what counts as a "whitespace error", whether git diff should look for whitespace errors, and how git diff should display whitespace errors if found. Search the documentation for the word "whitespace" to find these. See also Leonardo Dagnino's answer.

  • Related