我有一些需要使用LF行结尾的shell脚本(我使用的是Ubuntu 14.04)。由于这是一个跨平台的开源项目,因此使用了.gitattributes
文件来使行结尾自动工作。不幸的是,它们并没有起到作用。
$ 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 status
显示如下:$ git status .
[..]
nothing to commit, working directory clean
并且file
显示它没有改变:
$ 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结尾的文件?