为什么 Windows 用户想要将 LF 结尾转换为 CRLF?
Why would a Windows user want to convert LF endings to CRLF?
我正在处理 git 存储库中的 LF/CRLF 问题并阅读 git 的文档以尝试了解我需要做什么。
文档的一部分让我感到困惑:他们写 here:
...many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key. Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf
setting. If you’re on a Windows machine, set it to true
— this converts LF endings into CRLF when you check out code.
我不明白的是:如果我使用 Windows,我为什么要将行结尾从 LF 转换为 CRLF?会不会是因为我的编辑器不识别 LF 行结尾,因此将文件中的所有代码显示为一行?如果是这样,那么似乎如果我使用的编辑器 确实 识别此类 LF 行结尾并正确显示代码,即使文件正在使用 LF 行结尾,那么我会不需要进行 LF 到 CRLF 的转换,对吗?
如果您的编辑器支持 LF,并且您不关心可能想要为您的存储库做出贡献的其他人,那么是的,在大多数情况下,您不需要转换。
过去 20 年的任何体面的代码编辑器都应该处理 LF 文件。另一方面,记事本在很长一段时间内只支持 CRLF。固定在 Windows 10 1809.
可能仍然有一些命令行工具会在 LF 上阻塞,这也许是最大的问题; fopen
使用 Microsoft C run-time 的文本模式文件的命令行工具将输出 CRLF,即使在其代码中使用 \n
也是如此。
最后我想这是一个偏好问题,您希望潜在的转换错误发生在什么地方;在 git auto-conversion 或用于 parse/process 文件的工具中。
我正在处理 git 存储库中的 LF/CRLF 问题并阅读 git 的文档以尝试了解我需要做什么。
文档的一部分让我感到困惑:他们写 here:
...many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key. Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the
core.autocrlf
setting. If you’re on a Windows machine, set it totrue
— this converts LF endings into CRLF when you check out code.
我不明白的是:如果我使用 Windows,我为什么要将行结尾从 LF 转换为 CRLF?会不会是因为我的编辑器不识别 LF 行结尾,因此将文件中的所有代码显示为一行?如果是这样,那么似乎如果我使用的编辑器 确实 识别此类 LF 行结尾并正确显示代码,即使文件正在使用 LF 行结尾,那么我会不需要进行 LF 到 CRLF 的转换,对吗?
如果您的编辑器支持 LF,并且您不关心可能想要为您的存储库做出贡献的其他人,那么是的,在大多数情况下,您不需要转换。
过去 20 年的任何体面的代码编辑器都应该处理 LF 文件。另一方面,记事本在很长一段时间内只支持 CRLF。固定在 Windows 10 1809.
可能仍然有一些命令行工具会在 LF 上阻塞,这也许是最大的问题; fopen
使用 Microsoft C run-time 的文本模式文件的命令行工具将输出 CRLF,即使在其代码中使用 \n
也是如此。
最后我想这是一个偏好问题,您希望潜在的转换错误发生在什么地方;在 git auto-conversion 或用于 parse/process 文件的工具中。