git空白的困扰 [英] git whitespace woes

查看:514
本文介绍了git空白的困扰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空白的冲突



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

  git config apply.whitespace = strip 

似乎加快了冲突的可能性(因为您剥离了
不需要的空白,然后其他合作者将剥离的
空白作为对其提交的更改进行了修改?)。

我已经在
之前为 apply.whitespace 尝试了一些其他配置,也许其他配置之一解决了这个问题,或者有
其他设置来处理空白,我只是没有来
,但我还没有找到一个明确的方法来获得我想要的位置。



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



我从不想在空白处再次发生冲突。如果另一个
提交者改变了空格,或者我改变了空格,然后必须将
合并到我自己的冲突中,那么我真的不想知道它
如果有人将我的代码从K& R样式更改为One True Brace样式,使用
更改空格,我宁愿让git允许空白区设置赢得
以查看有关它的冲突。我只是不太在乎空白,想看到它的冲突。



所以......有什么方法可以配置git来完成那?



如果它有什么区别,这里是我的git版本,以及我当前的
配置:

  tchalvak:〜/ ninjawars $ git --version 
git版本1.6.0.4

tchalvak:〜/ ninjawars $
git config --list
color.branch = auto
color.diff = auto
color.status = auto
color.branch.current =黄色反转
color.branch.local =黄色
color.branch.remote =绿色
color.diff.meta =黄色粗体
color.diff.frag =洋红色粗体
color.diff .old =红色粗体
color.diff.new =绿色粗体
color.status.added =黄色
color.status.changed =绿色
color.status.untracked =青色
gui.recentrepo = / home / tchalvak / zd / htdocs / cms
apply.whitespace = strip
user.name = ****
user.email = *** *
alias.co =结帐
github.user = tchalvak
github.token = ****
core.repositoryformatversion = 0
core.filemode = true
core.bare = false
core.logallrefupdates = true
remote.origin.url = ... @ github.com:tchalvak/ninj awars.git
remote.origin.fetch = + refs / heads / *:refs / remotes / origin / *
branch.master.remote = origin
branch.master.merge = refs /首页/ master


解决方案

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 

它将忽略任何'空白'错误。

既然这样做不会阻止任何由于缺乏一致性而产生的冲突,但这可能值得尝试。 / p>




该补丁是一个测试:


仅忽略 t / tNNNN - *。sh t / tNNNN 子目录中的空白错误。 b



$ p $
其他文件(如测试库)应该仍然会被检查。

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+,Q1 2015,提交0a80bc9 ,由Junio C Hamano aka gitster git apply --whitespace = fix 不再沉默:


git apply --whitespace = fix 修复了公共
上下文行中的空白错误,但是没有报告就这样做了。



当传入的修补程序在公共上下文行中有空白错误时(即,一行预计会被找到并且不会被该修补程序修改), apply --whitespace = fix 修正了行所具有的空白错误,除了
然而,我们没有计算并报告我们在这样的行上修正了空白错误。


Conflicts on whitespace suck

Whitespace has ended up being a horrible pain for me while using 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.

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.

So... ...is there any way that I can configure git to do that?

If it makes any difference, here's my git version, and my current config:

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 

解决方案

Git1.6.0.4 seems a bit old, especially if you consider that:

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

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.

In a given directory, create a .gitattributes file.

* -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 the t/tNNNN subdirectories.
Other files (like test libraries) should still be checked.

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 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空白的困扰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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