【问题标题】:I always end up with mixed line-endings in Atom我总是以 Atom 中的混合行尾结尾
【发布时间】:2018-07-29 23:22:33
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: atom-editor line-endings


    【解决方案1】:

    您可以使用.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 来实现相同的目的。在团队或开源贡献者之间强制执行一致的设置特别有用。

    【讨论】:

    • 谢谢!我接受了你的回答,因为它更笼统
    【解决方案2】:

    我找到了一个包 (Force Line Endings) 可以满足我的需要。我想知道为什么其他人没有遇到同样的问题,以及为什么这个包的下载量如此之少。

    【讨论】:

      猜你喜欢
      • 2010-10-01
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多