From the git diff
documentation:
--check
Warn if changes introduce whitespace errors. What are considered whitespace errors is controlled by core.whitespace
configuration. By default, trailing whitespaces (including lines that solely consist 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. Exits with non-zero status if problems are found. Not compatible with --exit-code.
Correspondingly, the git config
documentation:
core.whitespace
A comma separated list of common whitespace problems to notice. git diff will use color.diff.whitespace
to highlight them, and git apply --whitespace=error will consider them as errors. You can prefix -
to disable any of them (e.g. -trailing-space
):
blank-at-eol
treats trailing whitespaces at the end of the line as an error (enabled by default).
space-before-tab
treats a space character that appears immediately before a tab character in the initial indent part of the line as an error (enabled by default).
indent-with-non-tab
treats a line that is indented with space characters instead of the equivalent tabs as an error (not enabled by default).
tab-in-indent
treats a tab character in the initial indent part of the line as an error (not enabled by default).
blank-at-eof
treats blank lines added at the end of file as an error (enabled by default).
trailing-space
is a short-hand to cover both blank-at-eol
and blank-at-eof
.
cr-at-eol
treats a carriage-return at the end of line as part of the line terminator, i.e. with it, trailing-space does not trigger if the character before such a carriage-return is not a whitespace (not enabled by default).
tabwidth=<n>
tells how many character positions a tab occupies; this is relevant for indent-with-non-tab and when Git fixes tab-in-indent errors. The default tab width is 8. Allowed values are 1 to 63.
As you can see, blank-at-eof
is enabled by default. You can disable it by adding -blank-at-eof
to the core.whitespace
configuration, or alternatively by using your own core.whitespace
configuration.