我有一些shell脚本需要LF行结尾(我在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状态显示如下:
$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终止文件?