【问题标题】:How to get Git to convert CRLF files to LF, on Linux?如何让 Git 在 Linux 上将 CRLF 文件转换为 LF?
【发布时间】:2015-02-14 01:32:44
【问题描述】:

我正在尝试做一些非常简单的事情:查看具有 CRLF 结尾(并且没有 .gitattributes)文件的 repo,并以本机 (LF) 行结尾结尾。我什至不想再承诺。

我读过 Github's suggestionTim Clem's article,但它们似乎主要针对 Windows 开发人员。

我试过这个:

$ git config --global core.autocrlf=input
$ git clone https://github.com/DennisSchiefer/Project-OSRM-Web.git

但是没有 - 我关心的文件 OSRM.Config.js 仍然有 CRLF 结尾。

尝试core.autocrlf=true 没有帮助。

即使添加和提交 .gitattributes 文件(然后是 git rm --cached -r . && git reset --hard)也无济于事。

我找不到任何组合实际上会在此文件上留下 LF 行结尾。

【问题讨论】:

    标签: linux git line-endings git-config


    【解决方案1】:

    core.autocrlf 将强制 git 处理所有 text 文件。

    如果 OSRM.Config.js 没有被处理,那意味着 Git 认为它是二进制的。
    见:

    即使使用.gitattributes*.js text,仍然会保留crlf

    但是对于*.js eol=lf,这实际上会强制转换。

    见“Can git's .gitattributes treat all files as binary except a few exceptions?”。

    【讨论】:

    • 在我的 .gitattributes 中的其他行中:*.js text
    • @SteveBennett text 表示crlf diff,如binary 表示-crlf -diff (stackoverflow.com/a/4264522/6309) matbe try *.js text lf diff?
    • @SteveBennett 或*.js eol=lf
    • @SteveBennett 很棒。我已将我的 cmets 包含在答案中以获得更多可见性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多