【问题标题】:How to change the behavior of git status showing modified files which are eventually not committed?如何更改 git status 显示最终未提交的已修改文件的行为?
【发布时间】:2015-11-29 03:44:26
【问题描述】:

我在一个纯 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 中无论如何都不会提交的更改,要么了解为什么这是不可能的。

【问题讨论】:

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


    【解决方案1】:

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

    根据您的问题,我了解到您希望使用 LF 来获取您的工作目录文件(=本地文件)。所以,在这里你应该使用core.autocrlf input。这将为您提供与存储库中完全相同的行尾(但仍会确保所有签入均使用LF)。

    answer中阅读更多关于真假输入的区别。

    【讨论】:

      猜你喜欢
      • 2013-04-24
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 2019-04-14
      • 2014-04-25
      • 2011-06-14
      • 2015-06-08
      • 2015-11-02
      相关资源
      最近更新 更多