【问题标题】:Git global settings and dealing with line endings once and for allGit 全局设置和一劳永逸地处理行尾
【发布时间】:2017-09-12 19:36:14
【问题描述】:

我到底应该在终端中写什么来全局配置我的 git 以保存所有文件总是以行结尾 = LF.我在 Windows 上工作,但我的大多数同事都使用 macOS,我想将我的所有工作保存在我的电脑上,行尾 = LF 设置

我找到了这个教程Dealing with line endings - GitHub help,但我仍然不知道我应该在终端中输入什么命令来配置 git 以使用该设置将所有克隆的项目保存在我的驱动器上。

你能帮帮我吗?

我试过了:

git config --global core.autocrlf true
git config --global core.autocrlf true text eol=lf

它没有用。

【问题讨论】:

    标签: git github


    【解决方案1】:

    如果您的编辑器使用 CRLF:

    git config --global core.autocrlf true

    如果你的编辑器使用 LF:

    git config --global core.autocrlf input

    您还可以在每个项目中使用 .gitattributes 文件来保存具有特定行尾的特定类型。我使用类似这样的东西,因为如果你使用* eol=lf

    ,git 会尝试在say 图像中转换 crlf 字节序列
    *.php eol=lf
    *.scss eol=lf
    *.sass eol=lf
    *.css eol=lf
    *.js eol=lf
    *.json eol=lf
    *.sql eol=lf
    

    【讨论】:

    • 值得注意的是,* text=auto eol=lf 从 Git 2.10 开始不会尝试转换非文本文件中的 CRLF 字节序列。 stackoverflow.com/a/40977008/1009155 换句话说:它在结帐时保持行尾不变,但仅在提交时将文本文件上的 CRLF 转换为 LF。因此,鉴于大多数 Windows 应用程序现在可以处理 LF 行结尾,这是一个不错的选择。
    • 换句话说,.gitattributes 中的* text=auto eol=lf 等价于git config 中的core.autocrlf input。同样,.gitattributes 中的* text=auto 等价于core.autocrlf true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2015-09-25
    • 2014-02-25
    • 2016-07-20
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多