【问题标题】:Which line ending/newline to use?使用哪个行尾/换行符?
【发布时间】:2026-02-09 07:15:02
【问题描述】:

网络上充斥着关于换行分裂历史的解释。但我无法找到答案,世界是否最终同意一个标准来结束一条线。

给定一个在 linux 和 windows 机器上开发和使用的 Java 项目。哪个是源文件中换行符的最佳选择:cr 还是 crlf?

将现有代码库中的所有 crlf 转换为 cr 是否有意义?是否可以与 SVN 到 Git 迁移一起执行此操作?

【问题讨论】:

标签: newline line-endings eol


【解决方案1】:

每个文件的 EOL 都是单独的

                                       | svn:eol-style |  Git attributes
For source code files --- native EOLs  |   native      |  !eol
For bash scripts --- LFs               |     LF        |  eol=lf
For bat scripts --- CRLFs              |    CRLF       |  eol=crlf
For binary files                       |  <not set>    |  -text

查看post about EOLs 了解详情。

还可以查看 SVNKit 存储库 (git clone http://svn.svnkit.com/git/svnkit) 中的 .gitattributes 作为在 EOL 中良好使用 Git 属性的示例。

【讨论】: