【问题标题】:PhpStorm + GIT line endings changing from LF to CRLFPhpStorm + GIT 行尾从 LF 更改为 CRLF
【发布时间】:2015-01-01 11:28:18
【问题描述】:

我已将我的 PhpStorm 行尾设置为 LF,但是当我提交到 github 时,有时我会看到一些文件再次以 CRLF 行尾出现(我在 Windows 上工作)。

它发生在我编辑过的相同文件上,并且在我提交/推送到存储库之间没有人编辑它们。这很烦人,我需要经常将行尾更改为同一个文件。它可能是什么以及如何解决它?

我还检查了选项“如果即将提交 CRLF 行分隔符则发出警告”

编辑

我的本​​地 git 配置是这样的:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = https://github.com/*
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

我的全局配置是这样的:

[user]
    name = *
    email = *
[core]
    autocrlf = false

我的系统范围配置是这样的:

[core]
    symlinks = false
    autocrlf = false
[color]
    diff = auto
    status = auto
    branch = auto
    interactive = true
[pack]
    packSizeLimit = 2g
[help]
    format = html
[http]
    sslCAinfo = /bin/curl-ca-bundle.crt
[sendemail]
    smtpserver = /bin/msmtp.exe

[diff "astextplain"]
    textconv = astextplain
[rebase]
    autosquash = true

还有我在 PhpStorm 中的 GIT 设置:

【问题讨论】:

    标签: git github phpstorm line-endings


    【解决方案1】:

    经过测试,显然不是 PhpStorm 问题,而是 GIT 配置问题。

    在 Windows 上似乎需要设置:

    git config --global core.autocrlf input
    

    还有

    git config --global core.eol lf
    

    让它工作。

    【讨论】:

      【解决方案2】:

      您可以检查此 Git 设置是否有帮助:

      git config --global core.autocrlf false
      

      我一般推荐keeping core.autocrlf to false(有only a few reason to set it to true)。

      还要检查您是否有任何带有core.eol 指令的.gitattributes 文件。

      【讨论】:

      • 我使用了git config --global --list,它确实设置为 true,所以我按照您的建议将其更改为 false。在我的.gitattributes 文件中,我只有* text=auto - 仅此而已。我将尝试查看此更改后问题仍然存在
      • 似乎根本没有帮助。我的文件中仍然有 CRLF。我查看了版本控制控制台,我看到了git -c core.quotepath=false config core.autocrlf,例如git -c core.quotepath=false add --ignore-errors -- tests/api/* warning: LF will be replaced by CRLF in tests/api/* The file will have its original line endings in your working directory.
      • @MarcinNabiałek git -c core.quotepath=false config core.autocrlf 似乎只强制设置此会话 autocrlf。这可以解释为什么忽略全局配置。
      • 那我该怎么办?我已经编辑了我的问题并添加了我从 PhpStorm 找到的配置和屏幕
      • @MarcinNabiałek 不确定,明天我会检查,但如果 PhpStorm 执行覆盖配置(尤其是 core.autocrlf)的 git 命令,那就不好了。
      【解决方案3】:

      git config --global core.autocrlf input 将确保 LF 仅适用于所有 git 项目。

      【讨论】:

        猜你喜欢
        • 2014-07-27
        • 1970-01-01
        • 2020-10-16
        • 2017-12-22
        • 2018-08-23
        • 2021-09-06
        • 2017-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多