linux 批量crlf转lf,为什么Git在Linux上将CRLF转换为LF?

我有一些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终止文件?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值