为什么Git在Linux上将CRLF转换为LF?

为什么Git在Linux上将CRLF转换为LF?,linux,git,line-endings,Linux,Git,Line Endings,我有一些shell脚本需要LF行结尾(我在Ubuntu 14.04上)。由于这是一个跨平台的开源项目,因此使用.gittributes文件“自动”使用行尾。不幸的是,他们没有 $ cat .gitattributes # automatically normalize line endings * text=auto 我的文件系统中有以下文件: $ file extract.sh extract.sh: Bourne-Again shell script, ASCII text execut

我有一些shell脚本需要LF行结尾(我在Ubuntu 14.04上)。由于这是一个跨平台的开源项目,因此使用
.gittributes
文件“自动”使用行尾。不幸的是,他们没有

$ cat .gitattributes
# automatically normalize line endings
* text=auto
我的文件系统中有以下文件:

$ file extract.sh 
extract.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
如果现在使用
dos2unix
处理它,它将正确显示为LF终止

$ file extract.sh 
extract.sh: Bourne-Again shell script, ASCII text executable
另外,
git
将其显示为已修改:

$ git status
[..]
Changes not staged for commit:
[..]

    modified:   extract.sh
现在我将其添加到索引中:

$ git add extract.sh 
warning: LF will be replaced by CRLF in extract.sh.
The file will have its original line endings in your working directory.
但是一个新的
git状态显示:

$ git status .
[..]

nothing to commit, working directory clean
文件
显示为未更改:

$ file extract.sh 
extract.sh: Bourne-Again shell script, ASCII text executable
但是,如果我将其删除并再次签出:

$ rm extract.sh 
$ git checkout extract.sh
$ file extract.sh 
extract.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
$ git status .
[..]

nothing to commit, working directory clean
即使将其从缓存中删除也无济于事:

$ git rm --cached extract.sh
$ git reset --hard
$ file extract.sh 
extract.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
100美元的问题是:如何让git给我一个以LF结尾的文件

如果您在Linux或Mac系统上使用LF行结尾,那么 不希望Git在签出文件时自动转换它们; 但是,如果意外引入了以CRLF结尾的文件, 那么您可能需要Git来修复它。您可以告诉Git将CRLF转换为 通过将core.autocrlf设置为 输入:

也看到
git config --global core.autocrlf input