问题
I don't want any non-functional changes like spacing, new lines, tabs in my commits. I used to use SVN which had a UI showing 2 screens (old file on left, file I'm about to commit on right) that let me quickly go through all my changes (down arrow) and change which way the arrow pointed (right meant commit it, left meant revert it back to how it was).
What are some similar, or even better ways to solve this problem in git?
回答1:
A setting like this one would do the trick:
git config apply.whitespace error
From git apply man page:
--whitespace=<action>
When applying a patch, detect a new or modified line that has whitespace errors.
What are considered whitespace errors is controlled bycore.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.By default, the command outputs warning messages but applies the patch. When
git-apply
is used for statistics and not applying a patch, it defaults tonowarn
.
You can use different<action>
values to control this behavior:
nowarn
turns off the trailing whitespace warning.warn
outputs warnings for a few such errors, but applies the patch as-is (default).fix
outputs warnings for a few such errors, and applies the patch after fixing them (strip is a synonym --- the tool used to consider only trailing whitespace characters as errors, and the fix involved stripping them, but modern Gits do more).error
outputs warnings for a few such errors, and refuses to apply the patch.error-all
is similar toerror
but shows all errors.
来源:https://stackoverflow.com/questions/19106131/git-efficient-way-to-prevent-commiting-non-functional-changes