首页 > 解决方案 > 我总是以 Atom 中的混合行尾结尾

问题描述

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

默认情况下它是 LF(这是我的首选),但在编辑过程中它有时会变成混合,然后我总是必须手动将其设置回 LF。

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

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

标签: atom-editorline-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 用户文档:处理行尾

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


推荐阅读