Popcorn
Popcorn

Reputation: 5348

GIT: efficient way to prevent commiting non-functional changes?

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?

Upvotes: 2

Views: 149

Answers (1)

VonC
VonC

Reputation: 1323065

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 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.

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 to nowarn.
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 to error but shows all errors.

Upvotes: 1

Related Questions