git 空白问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1316364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git whitespace woes
提问by Kzqai
Conflicts on whitespace suck
空白的冲突很糟糕
Whitespace has ended up being a horrible pain for me while using git.
在使用 git 时,空格对我来说是一个可怕的痛苦。
git config apply.whitespace=strip
seems to highten your chances of getting conflicts (as you strip unneeded whitespace and then other collaborators see the stripped whitespace as a change to their commits?)
似乎增加了您发生冲突的机会(因为您删除了不需要的空格,然后其他合作者将删除的空格视为对他们提交的更改?)
I've tried a few other configurations for apply.whitespace
in the
past, and maybe one of the other configs solves this, or maybe there's
other settings to deal with whitespace that I just haven't come
across, but I haven't yet found a clear way to get where I want to be.
我过去尝试过其他一些配置apply.whitespace
,也许其他配置之一解决了这个问题,或者可能还有其他设置来处理我没有遇到过的空白,但我还没有找到明确的到达我想去的地方的方式。
I want to silently resolve whitespace conflicts:
我想默默地解决空白冲突:
I never want to have another conflict on whitespace. If another committer alters whitespace, or I alter whitespace and then have to merge against my own conflicts, i really don't want to know about it. If someone changes my code from K&R style to One True Brace style by changing whitespace, I'd prefer git allow either whitespace setup to win out over having to see conflicts about it. I just don't care enough about whitespace to want to see conflicts about it.
我永远不想在空格上再发生冲突。如果另一个提交者改变了空格,或者我改变了空格然后不得不针对我自己的冲突进行合并,我真的不想知道。如果有人通过更改空格将我的代码从 K&R 样式更改为 One True Brace 样式,我更喜欢 git 允许任何一个空格设置胜过必须看到它的冲突。我只是不太关心空格,不想看到关于它的冲突。
So... ...is there any way that I can configure git to do that?
所以... ...有什么办法可以配置git来做到这一点?
If it makes any difference, here's my git version, and my current config:
如果有什么不同,这是我的 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
采纳答案by VonC
Git1.6.0.4seems a bit old, especially if you consider that:
Git1.6.0.4似乎有点旧,尤其是如果您考虑到:
- in 1.6.3.4, "
git apply --whitespace=fix
" did not fix trailing whitespace on an incomplete line - in 1.6.3.2, "
whitespace
" attribute that is set was meant to detect all errors known to git, but it told git to ignore trailing carriage-returns.
- 在1.6.3.4 中,"
git apply --whitespace=fix
" 没有修复不完整行的尾随空格 - 在1.6.3.2 中,设置的 "
whitespace
" 属性旨在检测 git 已知的所有错误,但它告诉 git 忽略尾随回车符。
Could you try with Git1.6.4.1, and rather than setting a global config, set an attribute on the files you want a special whitespace handle, like this patch describes.
您可以尝试使用 Git1.6.4.1,而不是设置全局配置,而是在您想要特殊空白句柄的文件上设置一个属性,就像这个补丁描述的.
In a given directory, create a .gitattributes
file.
在给定的目录中,创建一个.gitattributes
文件。
* -whitespace
which will ignore any 'whitespace' errors.
这将忽略任何“空白”错误。
Now that will not prevent any conflict due to lack of consistency but that may be worth trying.
现在这不会阻止由于缺乏一致性而导致的任何冲突,但这可能值得一试。
The patch was a test about:
该补丁是关于以下内容的测试:
Only ignore whitespace errors in
t/tNNNN-*.sh
and thet/tNNNN
subdirectories.
Other files (like test libraries) should still be checked.
仅忽略
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
Note (Git 2.3.2+, Q1 2015, commit 0a80bc9, by Junio C Hamano aka gitster
) "git apply --whitespace=fix
" is no longer silent:
注意(Git 2.3.2+, Q1 2015, commit 0a80bc9, by Junio C Hamanoaka gitster
)“ git apply --whitespace=fix
”不再沉默:
"
git apply --whitespace=fix
" fixed whitespace errors in the common context lines but did so without reporting.When the incoming patch has whitespace errors in a common context line (i.e. a line that is expected to be found and is not modified by the patch), "
apply --whitespace=fix
" corrects the whitespace errors the line has, in addition to the whitespace error on a line that is updated by the patch.
However, we did not count and report that we fixed whitespace errors on such lines.
"
git apply --whitespace=fix
" 修复了常见上下文行中的空白错误,但没有报告。当传入的补丁在公共上下文行(即预期会被找到且未被补丁修改
apply --whitespace=fix
的行)中存在空白错误时,除了行上的空白错误之外,“ ”更正该行具有的空白错误由补丁更新。
但是,我们没有计算和报告我们修复了这些行上的空白错误。
回答by SteveS
If you are going to turn on those settings, you need to schedule a day where ALL source code in your project gets its whitespace uniformly stripped, by running a script, or by saving every file from an editor that will perform the strip on save. Then, all future commits will be policed by the settings, so all should be well going forward.
如果您要打开这些设置,您需要安排一天,通过运行脚本或从将在保存时执行删除的编辑器中保存每个文件,来统一删除项目中的所有源代码的空白。然后,所有未来的提交都将受到设置的监管,所以一切都应该顺利进行。