git whitespace woes

Kzq*_*qai 34 git settings whitespace

空白的冲突很糟糕

在使用git时,空白对我来说是一种可怕的痛苦.

git config apply.whitespace=strip
Run Code Online (Sandbox Code Playgroud)

似乎会增加你获得冲突的机会(当你删除不需要的空格,然后其他合作者将剥离的空白视为对其提交的更改?)

我过去曾尝试过其他一些配置apply.whitespace,也许其他配置中的一个可以解决这个问题,或者可能还有其他设置来处理我刚才没有遇到的空白,但我还没有找到明确的如何到达我想要的地方.

我想默默地解决空白冲突:

我从不想在空白上再发生冲突.如果另一个提交者改变了空格,或者我改变了空格然后必须合并我自己的冲突,我真的不想知道它.如果有人通过更改空格将我的代码从K&R样式更改为One True Brace样式,我更喜欢git允许空白设置赢得而不必看到它的冲突.我只是不太关心空白想要看到它的冲突.

所以......有什么方法可以配置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
remote.origin.url=...@github.com:tchalvak/ninjawars.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master 
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 17

Git1.6.0.4似乎有点旧,特别是如果你考虑到:

  • 1.6.3.4中," git apply --whitespace=fix"没有修复不完整行上的尾随空格
  • 1.6.3.2中,设置的" whitespace"属性旨在检测git已知的所有错误,但它告诉git忽略尾随回车.

你可以尝试使用Git1.6.4.1,而不是设置一个全局配置,在你想要一个特殊的空白句柄的文件上设置一个属性,就像这个补丁所描述的那样.

在给定目录中,创建一个.gitattributes文件.

* -whitespace
Run Code Online (Sandbox Code Playgroud)

这将忽略任何'空白'错误.

现在,这不会阻止由于缺乏一致性而导致的任何冲突,但这可能值得尝试.


这个补丁是一个测试:

只有忽略空格错误t/tNNNN-*.sht/tNNNN子目录.
仍应检查其他文件(如测试库).

t/.gitattributes
t[0-9][0-9][0-9][0-9]-*.sh  -whitespace
t[0-9][0-9][0-9][0-9]/*     -whitespace
Run Code Online (Sandbox Code Playgroud)

注意(Git 2.3.2 +,2015年第1季,提交0a80bc9,由Junio C Hamano aka gitster)" git apply --whitespace=fix"不再沉默:

" git apply --whitespace=fix"修复了常见上下文行中的空白错误,但没有报告.

当进入的贴剂具有在一个共同的上下文线的空白的错误(即,预期被发现,而不是由贴片改性的线)," apply --whitespace=fix"校正空白错误的行有,除了空白错误上的线由补丁更新.
但是,我们没有计算并报告我们在这些行上修复了空白错误.


Ste*_*veS 8

如果要打开这些设置,则需要安排一天,项目中的所有源代码都会通过运行脚本或通过保存编辑器中的每个文件来保存空白区域.然后所有未来的提交都将受到设置的监管,因此所有提交都应该很好.