GIT:阻止提交非功能性更改的有效方法? [英] GIT: efficient way to prevent commiting non-functional changes?

查看:105
本文介绍了GIT:阻止提交非功能性更改的有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望我的提交中有任何非功能性更改,例如间距,换行符,制表符。我曾经使用过SVN,它有一个显示2个屏幕的UI(左边的旧文件,我正要在右边提交的文件),让我快速浏览所有的改变(向下箭头),并改变箭头指向的方向意味着承诺它,左意味着恢复到它是如何)。

什么是一些类似的,甚至更好的方法来解决这个问题?在git中?

解决方案

设置就像这样:

  git config apply.whitespace错误

git apply 手册页

   -  whitespace =< action> 




应用修补程序时,检测具有空白的新行或修改过的行错误。

认为空白错误由 core.whitespace 配置控制。

By默认情况下,尾部空格(包括仅由空白部分组成的行)和空格字符紧接在该行的初始缩进内部的制表符之后被认为是空白错误


$ b

默认情况下,该命令输出警告消息但应用修补程序。当 git-apply 用于统计数据而不应用补丁时,它默认为 nowarn

您可以使用不同的< action> 值来控制此行为:




  • nowarn 将关闭尾部空白警告。 > 警告 会输出警告以获得一些此类错误,但会按原样应用修补程序(默认)。 strong> fix 输出一些此类错误的警告,并在修复后应用修补程序(strip是同义词---该工具仅用于考虑跟踪空白字符作为错误,修复涉及剥离它们,但现代Gits做得更多)。 >输出一些此类错误的警告,并拒绝应用该修补程序。
  • 类似于错误,但显示所有错误。

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?

解决方案

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.

这篇关于GIT:阻止提交非功能性更改的有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆