强制SourceTree忽略git文件中的行尾符号问题

16

有很多帖子,但是分辨率仍然不清晰或者对我没有用。问题似乎很常见。

  1. 我在Unix中检查了我的项目,git状态没有显示任何差异。

bash-3.2$ git config core.autocrlf
false
bash-3.2$ git config core.whitespace
cr-at-eol
  • 但我也喜欢使用SourceTree(通过NFS挂载指向同一的Unix代码库)获得一些便利。 上述属性的设置完全相同。
    但是,基于纯粹的行结尾,SourceTree显示了许多差异。

  • 这个问题有什么简单的解决方案?
    为什么SourceTree在UI中没有针对这个问题的设置?


    使用十六进制编辑器打开文件,查看真实的结束符。在Windows上,你应该有CRLF(无论数字是多少,它都是2个字符)。从Git中提取的Unix机器上的代码可能有LF。这会产生不同之处。Git被“训练”将该代码视为相等,但SourceTree则不然。 - Nick Volynkin
    即使我从SourceTree提供的shell中运行“git status”,它也会显示这些差异。问题是如何强制SourceTree忽略这些差异? - endless
    我完全不知道如何配置SourceTree,也不确定是否有可能。但是,如果你使用Git在开发者之间交换代码,你可以设置Git来处理行尾。 - Nick Volynkin
    我刚在一个类似的问题上提出了一些建议,希望能对你有所帮助。http://stackoverflow.com/questions/30603750/git-picking-up-whitespace-changes-it-shouldnt?noredirect=1#comment49278669_30603750 - Nick Volynkin
    我有两台机器,安装了完全相同版本的 gitsourcetreeapp。其中一台机器的源树忽略了行尾差异,而另一台机器由于行尾差异显示整个文件已更改。我不知道是什么原因导致这种情况... - Zennichimaro
    1个回答

    17

    在SourceTree应用程序的diff-ui部分附近有一个齿轮图标,显示文件差异,您可以单击它并设置为显示空格忽略空格!我搜索了几个小时,最终在寻找git命令的SourceTree等效命令后得到了答案:

    Git version <= 1.8.3.4:
    git diff --ignore-space-at-eol -b -w [commit] ...
    
    Git version >= 1.8.4:
    git diff --ignore-space-at-eol -b -w --ignore-blank-lines [commit] ...
    
    See the options definition below:
    
    --ignore-space-at-eol 
    Ignore changes in whitespace at EOL.
    
    -b 
    --ignore-space-change 
    Ignore changes in amount of whitespace. This ignores whitespace at line end, 
    and considers all other sequences of one or more whitespace characters to be 
    equivalent.
    
    -w 
    --ignore-all-space 
    Ignore whitespace when comparing lines. This ignores differences even if one 
    line has whitespace where the other line has none.
    
    [git version 1.8.4+]--ignore-blank-lines 
    Ignore changes whose lines are all blank.
    

    截图

    参考文献:

    Git 命令的等效操作

    Source Tree 应用程序设置


    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接