在使用git的过程中,whitespace对我来说是一个可怕的痛苦。
git config apply.whitespace=strip
似乎增加了冲突的几率(因为你把不需要的whitespace去掉,然后其他合作者会认为去掉的whitespace是对他们的提交进行了修改?
我试过一些其他的配置,如 apply.whitespace
也许有其他的配置可以解决这个问题,也许有其他的设置来处理空白,但我还没有遇到,但我还没有找到一个明确的方法来达到我想要的目的。
我不想再在空白处发生冲突。 如果另一个committer改变了whitespace,或者我改变了whitespace,然后不得不对我自己的冲突进行报复。我真的不想知道这件事.如果有人通过改变whitespace把我的代码从K&R风格改成One True Brace风格,我更希望git允许任何一种whitespace的设置,而不是让我看到关于它的冲突。我只是不关心whitespace,不想看到它的冲突。
所以......有什么办法可以让我配置git来做到这一点吗?
如果有什么不同的话,这是我的git版本和当前的配置。
tchalvak:~/ninjawars$ git --version
git version 1.6.0.4
tchalvak:~/ninjawars$
git config --list
color.branch=auto
color.diff=auto
color.status=auto
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.meta=yellow bold
color.diff.frag=magenta bold
color.diff.old=red bold
color.diff.new=green bold
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
gui.recentrepo=/home/tchalvak/zd/htdocs/cms
apply.whitespace=strip
user.name=****
user.email=****
alias.co=checkout
github.user=tchalvak
github.token=****
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[email protected]:tchalvak/ninjawars.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
git1.6.0.4 似乎有点老,尤其是当你考虑到这一点时。
git apply --whitespace=fix
"没有修正不完整行上的尾部空白。whitespace
"属性的设置是为了检测所有git知道的错误,但它告诉git忽略了尾部的回车。你能不能用 Git1.6.4.1 试试,不要设置全局配置,而是在需要特殊空白处理的文件上设置一个属性,比如说 补丁描述.
在给定的目录中,创建一个 .gitattributes
文件,它将忽略任何 "空格 "错误。
* -whitespace
它将忽略任何 "空格 "错误。
现在,这不会防止任何由于缺乏一致性而导致的冲突,但这可能值得一试。
这个补丁是一个关于测试。
只忽略空格错误
t/tNNNN-*.sh
和t/tNNNN
子目录。 其他文件(如测试库)仍应检查。
t/.gitattributes
t[0-9][0-9][0-9][0-9]-*.sh -whitespace
t[0-9][0-9][0-9][0-9]/* -whitespace
注(Git 2.3.2+,2015年第一季度。提交 0a80bc9滨野淳夫又名 gitster
) "git apply --whitespace=fix
"不再沉默。
"
git apply --whitespace=fix
"修正了常见上下文行中的空白错误,但没有报告。当传入的补丁在共同上下文行中出现空白错误时(即预计会被发现但未被补丁修改的行),"
apply --whitespace=fix
"纠正了该行存在的空白错误,此外,还纠正了被补丁更新的行上的空白错误。 然而,我们并没有统计和报告我们修复了这类行上的whitespace错误。
如果你要开启这些设置,你需要安排一天的时间,让你项目中的所有源代码都被统一去掉whitespace,通过运行一个脚本,或者从编辑器中保存每个文件,在保存时执行去掉。 然后,所有未来的提交都会受到这些设置的控制,所以一切都会顺利进行。