【问题标题】:Force SourceTree ignore line endings in git files强制 SourceTree 忽略 git 文件中的行尾
【发布时间】:2015-06-02 18:06:25
【问题描述】:

有这么多帖子,但分辨率仍不清楚或不适合我。问题似乎众所周知..

  1. 我在 unix 中检查了我的项目,并且 git status 没有显示任何差异。 此处设置:

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

什么是直接的解决方案?
为什么 SourceTree 在 UI 中没有这个设置?

【问题讨论】:

  • 用十六进制编辑器打开你的文件,看看什么是真正的尾行字符。在 Windows 上,您应该有 CRLF(无论数字是多少,都是 2 个字符)。从 git 提取的 Unix 机器上的代码可能有 LF。这会有所不同。 Git 被“训练”以看到代码是平等的,而 SourceTree 不是。
  • 即使我从 SourceTree 提供的 shell 运行“git status”,它也会显示这些差异。问题是如何强制 SourceTree 忽略这些差异?
  • 我不知道如何配置 SourceTree 以及是否可能。但是如果你在开发者之间使用 Git 交换代码,你可以设置 Git 来处理 endlines。
  • 刚刚对一个类似的问题提出了一些建议,希望对您有所帮助。 stackoverflow.com/questions/30603750/…
  • 我有两台机器安装了完全相同版本的gitsourcetreeapp。一台机器的源代码树忽略行尾差异。由于行尾不同,另一台机器显示整个文件已更改。不知道是什么原因造成的...

标签: git atlassian-sourcetree line-endings


【解决方案1】:

SourceTree 应用程序的 diff-ui 部分附近有一个 gear icon 显示您的文件差异,您可以单击它并将其设置为 show whitespaceignore whitespace!我google了几个小时,终于在搜索了相当于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.

参考资料:

The git command equivalent

Source Tree app settings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2013-05-26
    • 1970-01-01
    相关资源
    最近更新 更多