7

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

4

1 回答 1

1

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

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

在这个答案中阅读更多关于真假输入的区别。

于 2015-09-08T20:39:54.347 回答