I'm writing a README.md
. I've added an extra space at the end of some lines. When I do git diff
shows this as highlighted as below
Why the trailing whitespace is considered an error?
I'm writing a README.md
. I've added an extra space at the end of some lines. When I do git diff
shows this as highlighted as below
Why the trailing whitespace is considered an error?
One reason I can think of is the line ending styles for git.
The question git diff - show me line ending changes? asked can be of some help as well.
Git will show you "common whitespace problems" such as trailing whitespace. You can control this behavior with the core.whitespace
configuration option. -trailing-space
will turn this highlighting off.
[core]
whitespace = -trailing-space
I've never understood why this is considered a problem, but many people do, so I recommend stripping them off. You can configure your editor to strip trailing whitespace for you. If doing this for all documents doesn't appeal to you, use EditorConfig to provide universal editor configurations for your projects.
root = true
[*]
trim_trailing_whitespace = true
insert_final_newline = true
See also