【问题标题】:git ignore line endingsgit忽略行尾
【发布时间】:2015-07-27 13:06:16
【问题描述】:

我知道有人问过类似的问题,但我仍然无法解决问题。

我的项目在使用不同操作系统的人之间共享,我在 OSX 上。此外,并不是每个人都使用 git,我有时不得不提交其他人的更改。

有时,git 突然说有待处理的更改。查看它们看起来相同的文件:

@@ -1,6 +1,6 @@
-<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
->
-    <Deployment.Parts>
-    </Deployment.Parts>
-</Deployment>
+<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+>
+    <Deployment.Parts>
+    </Deployment.Parts>
+</Deployment>

我怀疑这些是行尾问题。

[编辑] 一个外部 diff 工具明确表示:“状态:1 差异行尾不同 - 左:Windows (CRLF),右:Unix (LF)”

根据一些在线提示,我的配置如下:

[core]
    excludesfile = /Users/nathanh/.gitignore_global
    autocrlf = input
    attributesfile = /Users/nathanh/.config/git/attributes
    whitespace = cr-at-eol

还有我的属性文件:

# Ignore all differences in line endings
*        -crlf

为什么仍然显示文件已修改?

【问题讨论】:

  • 如果您未设置 core.filemode 或设置为 true,输出是否不同?您也可以尝试禁用 core.whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol;
  • 问题之一是我需要做什么才能应用这些更改?
  • 取消设置文件模式:尝试 git config core.fileMode false

标签: git line-endings


【解决方案1】:

从 JetBrains.com 阅读本文

要让Git自动解决此类问题,需要在Windows上将core.autocrlf属性设置为true,在Linux和OS X上设置为input。关于core.autocrlf属性含义的更多详细信息,请参阅文章@ 987654321@。您可以通过运行手动更改配置

git config --global core.autocrlf true 

在 Windows 上或

git config --global core.autocrlf input 

在 Linux 和 OS X 上。但是,IntelliJ IDEA 可以分析您的配置,在您将 CRLF 提交到存储库时发出警告,并根据所使用的操作系统将 core.autocrlf 设置设置为 true 或输入.

希望这可能会对问题有所启发。

【讨论】:

  • 对不起,不小心把这个答案发了两次 :(
  • 所以这假设其他人也需要在他们的计算机上执行此操作。问题之一是有时我通过其他方式获取 Windows 文件,然后我从我的 mac 提交它们。
  • 这也要冷静git diff吗?它不适合我,但我是 git 新手,所以也许我做得不对。
  • 如果配置不应该是全局添加的,只需运行git config core.autocrlf true resp。 git config --global core.autocrlf input
猜你喜欢
  • 1970-01-01
  • 2010-10-26
  • 1970-01-01
  • 2011-05-20
  • 2014-10-17
  • 1970-01-01
  • 2017-02-06
相关资源
最近更新 更多