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

ε祈祈猫儿з 提交于 2020-01-23 16:56:30

问题


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


来源:https://stackoverflow.com/questions/19106131/git-efficient-way-to-prevent-commiting-non-functional-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!