【发布时间】:2014-07-01 12:37:24
【问题描述】:
我有一些需要 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 终止的文件?
【问题讨论】:
-
另见this
标签: linux git line-endings