windows - 如何更改 git status 显示最终未提交的已修改文件的行为?

标签 windows git end-of-line core.autocrlf

我在纯 Windows 工作环境中工作,开发人员使用各种工具来编辑他们的文件。我们正在使用 .git 以及 atlassian 堆栈来对我们的代码进行版本控制。我几乎都喜欢。

我最近刚刚结束了一场漫长而艰苦的战斗,以全神贯注于 git 如何以及为什么解释行尾以及 core.autocrlf 的作用。我们决定使用 core.autocrlf true 并且几乎一切正常。

我很想知道如何改变 git status 的这种行为:

  • 我有一个带有 CRLF 行结尾的文件。
  • 我将行结尾更改为 LF

    $ git status
    On branch somebranch
    Changes not staged for commit:
        (use "git add <file>..." to update what will be committed)
        (use "git checkout -- <file>..." to discard changes in working directory)
    
    modified:   Src/the_file_i_changed_to_LF.js
    
  • 但是……

    $ git commit -a
    warning: LF will be replaced by CRLF in Src/the_file_i_changed_to_LF.js.
    The file will have its original line endings in your working directory.
    On branch somebranch
    nothing to commit, working directory clean
    

给这个:

  • 我有一个带有 CRLF 行结尾的文件。
  • 我将行结尾更改为 LF

    $ git status
    On branch somebranch
    nothing to commit, working directory clean
    
  • 这是有道理的,因为无论如何都不会提交任何内容。

这可能吗?

我相信可能的重复项不包含我正在寻找的答案。我想强调的是,我确实(认为我)知道我的设置 core.autocrlf true 的作用,并希望保持这种状态。我感兴趣的是要么不检测 git status 中无论如何都不会提交的更改,要么理解为什么这是不可能的。

最佳答案

当您设置 core.autocrlf true 时,您工作目录中的所有文件都将以 CRLF 行结尾(忽略存储库中的实际行结尾)。对于大多数 Windows 用户来说,这已经足够了。

根据你的问题,我了解到你希望你的工作目录文件(=本地文件)具有 LF。所以,在这里你应该使用 core.autocrlf input。这将为您提供与存储库中一样的确切行结尾(但它仍然会确保所有 checkin 都是使用 LF 进行的)。

在此 answer 中阅读更多有关 true、false 和 input 的区别的信息.

关于windows - 如何更改 git status 显示最终未提交的已修改文件的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32373384/

相关文章:

regex - 将行尾 (EOL) 与 vim 中的语法匹配

时间:2019-05-09 标签:c#复制文本到行尾richtextbox

javascript - 正则表达式从整行或仅到给定的标记创建一个组

javascript - Window Active Directory React JS 自动身份验证

python - nslookup 在 python 中使用服务器替代方案

c - Xcode 中的 Git 忽略

Git:主重置后分支会发生什么

windows - 使用 perl/cmd 窗口查找 ram 类型

windows - 在 Windows 10 64 位中注册 DLL 而不将其移动到 System32

java - sed: 1: "./.classpath": 无效的命令代码。错误。有什么问题吗?