我总是以 Atom 中的混合行结尾结尾

I always end up with mixed line-endings in Atom

我安装了一个包 (Line Ending Selector),它可以告诉我文件中使用了哪些行结尾(LF 或 CRLF 或混合)。

默认是LF(我比较喜欢),但在编辑过程中有时会变成Mixed,然后我总是不得不手动将它设置回LF。

当我忘记将所有行尾设置回 LF、将文件推送到具有混合行尾的 Github 时,有人拉取它、推送他们的更改,而该提交的一半只是他们的编辑器对文件所做的行结束更改,因为它具有自动行结束更正 - 与我的不同。

Atom 也可以有这个功能吗?有没有办法确保(例如在保存时)文件的所有行结尾都设置为 LF?

我找到了一个完全符合我需要的程序包 (Force Line Endings)。我想知道为什么其他人没有同样的问题,为什么这个包的下载量这么少。

你可以利用.gitattributes来处理行尾:

    # Set the default behavior, in case people don't have core.autocrlf set.
    * text=auto

    # Explicitly declare text files you want to always be normalized and converted
    # to native line endings on checkout.
    *.c text
    *.h text

    # Declare files that will always have CRLF line endings on checkout.
    *.sln text eol=crlf

    # Denote all files that are truly binary and should not be modified.
    *.png binary
    *.jpg binary

相关: GitHub User Documentation: Dealing with line endings

或者,您可以使用 EditorConfig 来实现相同的目的。在团队或开源贡献者之间实施一致的设置特别有用。