【问题标题】:Git doesn't change line-endings after creating .gitattributes fileGit 在创建 .gitattributes 文件后不会更改行尾
【发布时间】:2014-10-16 09:58:12
【问题描述】:

我想设置 git 以将所有 LF 结尾更改为 CRLF。

我在我的 repo 的根文件夹中创建了一个 .gitattributes 文件:

* text=auto 
# Have git change every .groovy and .java file to crlf
*.java eol=crlf
*.groovy eol=crlf

当提交一个我知道有 LF 结尾的 .java 文件时,我希望在签出到新的本地分支时它会更改为 CRLF。但事实并非如此。有什么想法吗?

【问题讨论】:

    标签: git newline


    【解决方案1】:

    我相信您需要在“eol”属性之前指定“text”;因此您的示例将变为以下内容:

    * text=auto 
    # Have git change every .groovy and .java file to crlf
    *.java text eol=crlf
    *.groovy text eol=crlf
    

    【讨论】:

    • 恐怕这行不通。您的 .gitattributes 和我的实际上没有区别。
    • 嗯,尝试在全局配置中设置 autoclrf$ git config --global core.autocrlf true
    • git config 是我机器上存储库的本地更改。尽管这可能对我有用,但我需要为团队项目修复此设置。
    • 您应该也可以在您的主存储库上运行它,前提是您可以通过 bash 访问它。它似乎在我的裸主人身上运行良好。
    【解决方案2】:

    所以我发现了问题。我正在使用 Egit,其中 .gitattributes 目前还没有得到正确支持。 见This Link。目前未解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 2019-04-11
      相关资源
      最近更新 更多