Commit Diffs on GIT normally show trailing whitespaces if set to colored diffs.

$ vim ~/.gitconfig
        ui = auto
[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green
[color "diff"]
        meta = blue bold
        frag = magenta bold
        old = red bold
        new = green bold
[color "status"]
        added = yellow
        changed = green
        untracked = cyan

        ui = true
[color "diff"]
        whitespace = red reverse

In order to remove them, the following tips can be used:

Remove trailing whitespaces (at the end):


Delete whitespace at the beginning of each line:

" Same thing (:le = :left = left-align given range):

To detect them, just put this in your vimrc – before any highlight command:

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /s+$/
match ExtraWhitespace /s+%#@<!$/
match ExtraWhitespace /s+$/
%d bloggers like this: