# [RFC] Representation of diff with trailing spaces

3 messages from 2020-03-26 to 2020-03-26. Participants: Sébastien BRUCKERT, Jeff King.
Thread: https://gitlist.dev/t/53107

## Sébastien BRUCKERT, 2020-03-26 11:07

Subject: [RFC] Representation of diff with trailing spaces
Message-ID: <CABt=S26FB1zkwDCdmXeyVvFYvpvuGSX_y1Fg5N3K=yq0ZMyR7A@mail.gmail.com>
URL: https://gitlist.dev/e/CABt%3DS26FB1zkwDCdmXeyVvFYvpvuGSX_y1Fg5N3K%3Dyq0ZMyR7A%40mail.gmail.com

```
Hello everyone,

This is my first RFC, I hope it is correct. Do not hesitate to correct me.

# Problem
Trailing spaces are represented only when added in the diff, and not
when removed.


# Abstract
Something that always bothered me with git diff was how trailing
spaces are represented. If I add spaces, then diff, they are
represented in the terminal by a red background. If I then remove
them, they are not represented. That's how I can have a diff with two
exact lines, and I'm looking for the diff in it, but can't find it.
Because it is the non-represented spaces.

# Reproducibility
One picture is worth a thousand words, here is a little snippet of
shell to see this by yourself:
ˋˋˋ
mkdir test
cd test

git init

cat << EOF > file
This file contains line at the end before fix.
EOF

git add file
git diff --staged

sed -i 's/[[:blank:]]*$//' file

git add -p
ˋˋˋ

# Solution proposed
Show the trailing spaces in a diff when removed.
No performance impact expected,

# Open point
Maybe we could argue on which color for added trailing spaces, and
removed ones, to differentiate them quickly in a big diff. For the
moment, added spaces are red. Maybe they should be green, and removed
should be red. Or the opposite. Or everything in red.


Thank you for taking the time to review my proposal!

```

## Jeff King, 2020-03-26 11:15

Subject: Re: [RFC] Representation of diff with trailing spaces
Message-ID: <20200326111500.GB4193632@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20200326111500.GB4193632%40coredump.intra.peff.net
In-Reply-To: <CABt=S26FB1zkwDCdmXeyVvFYvpvuGSX_y1Fg5N3K=yq0ZMyR7A@mail.gmail.com>

```
On Thu, Mar 26, 2020 at 12:07:55PM +0100, Sébastien BRUCKERT wrote:

> # Abstract
> Something that always bothered me with git diff was how trailing
> spaces are represented. If I add spaces, then diff, they are
> represented in the terminal by a red background. If I then remove
> them, they are not represented. That's how I can have a diff with two
> exact lines, and I'm looking for the diff in it, but can't find it.
> Because it is the non-represented spaces.

Have you tried setting diff.wsErrorHighlight? By default we only
highlight whitespace problems in new lines, but it can be told to show
them in old lines or in context.

-Peff

```

## Sébastien BRUCKERT, 2020-03-26 12:40

Subject: Re: [RFC] Representation of diff with trailing spaces
Message-ID: <CABt=S24vy0QpuVHoXdzTcRb3r6mU1AdswrGxOPksdwdrBGpEBg@mail.gmail.com>
URL: https://gitlist.dev/e/CABt%3DS24vy0QpuVHoXdzTcRb3r6mU1AdswrGxOPksdwdrBGpEBg%40mail.gmail.com
In-Reply-To: <20200326111500.GB4193632@coredump.intra.peff.net>

```
> > # Abstract
> > Something that always bothered me with git diff was how trailing
> > spaces are represented. If I add spaces, then diff, they are
> > represented in the terminal by a red background. If I then remove
> > them, they are not represented. That's how I can have a diff with two
> > exact lines, and I'm looking for the diff in it, but can't find it.
> > Because it is the non-represented spaces.
>
> Have you tried setting diff.wsErrorHighlight? By default we only
> highlight whitespace problems in new lines, but it can be told to show
> them in old lines or in context.
>
> -Peff

Oh yes, that was what I was looking for, thank you Peff!

Well, if there is a config for it then, no need to change anything.

```
