LF 将被 git 中的 CRLF 取代 - 那是什么,它很重要吗? [英] LF will be replaced by CRLF in git - What is that and is it important?

查看:38
本文介绍了LF 将被 git 中的 CRLF 取代 - 那是什么,它很重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个新的 rails 应用程序时,我在 git 中看到一个关于 LF 替换的警告.我愿意混帐初始化git 添加.

When I create a new rails application I'm seeing a warning in git about LF replacement. I do git init git add .

然后繁荣!我看到几乎所有文件都会弹出这个.我通常只是继续构建我的应用程序,并且在对文件进行多次更改后它就会消失.

and then boom! I see this pop up for almost all files. I usually just keep going and build my application and it disappears after many changes to files.

示例:

该文件将在您的工作目录中以原始行结尾.警告:LF 将被 Gemfile 中的 CRLF 替换.

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in Gemfile.

该文件将在您的工作目录中以原始行结尾.警告:LF 将被 Gemfile.lock 中的 CRLF 替换.

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in Gemfile.lock.

该文件将在您的工作目录中以原始行结尾.警告:LF 将被 README 中的 CRLF 替换.

The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in README.

LF 和 CRLF 有什么区别?

What's the difference between LF and CRLF?

从长远来看,我应该担心这个问题,还是应该忽略它并像往常一样继续?

Should I be concerned about this in the long run or just ignore it and keep going as I usually do?

推荐答案

在 Unix 系统中,行尾用换行符 (LF) 表示.在 Windows 中,一行用回车 (CR) 和换行 (LF) 表示 (CRLF).当您从 git 获取从 unix 系统上传的代码时,它们将只有一个 LF.

In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.

如果您是在 windows 机器上工作的单个开发人员,并且您不关心 git 自动将 LFs 替换为 CRLFs,您可以通过在 git 命令行中键入以下内容来关闭此警告

If you are a single developer working on a windows machine, and you don't care that git automatically replaces LFs to CRLFs, you can turn this warning off by typing the following in the git command line

git config core.autocrlf true

如果你想明智地决定 git 应该如何处理这个问题,阅读文档

If you want to make an intelligent decision how git should handle this, read the documentation

这是一个片段

格式和空格

格式和空白问题是一些更令人沮丧和许多开发人员在协作时遇到的细微问题,尤其是跨平台.补丁或其他协作工作以引入细微的空白变化,因为编辑默默地介绍他们,如果你的文件曾经触及Windows 系统,它们的行尾可能会被替换.Git有几个有助于解决这些问题的配置选项.

Formatting and whitespace issues are some of the more frustrating and subtle problems that many developers encounter when collaborating, especially cross-platform. It’s very easy for patches or other collaborated work to introduce subtle whitespace changes because editors silently introduce them, and if your files ever touch a Windows system, their line endings might be replaced. Git has a few configuration options to help with these issues.

core.autocrlf

如果您在 Windows 上编程并与不熟悉 Windows 的人一起工作(或反之亦然),您可能会在某些时候遇到行尾问题观点.这是因为 Windows 使用回车符以及文件中换行符的换行符,而 Mac 和Linux 系统仅使用换行符.这是一个微妙但跨平台工作令人难以置信的恼人事实;许多编辑在Windows 默默地用 CRLF 替换现有的 LF 样式行结尾,或当用户按下回车键时插入两个行尾字符.

If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas Mac and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; 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 可以通过将 CRLF 行尾自动转换为 LF 来处理这个问题您将文件添加到索引,反之亦然,当它检出代码时到你的文件系统.您可以使用core.autocrlf 设置.如果您使用的是 Windows 计算机,请将其设置为 true– 当您签出代码时,这会将 LF 结尾转换为 CRLF:

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:

$ git config --global core.autocrlf true

如果您使用的是使用 LF 行结尾的 Linux 或 Mac 系统,那么您不希望 Git 在您签出文件时自动转换它们;但是,如果意外引入了带有 CRLF 结尾的文件,那么你可能希望 Git 修复它.您可以告诉 Git 将 CRLF 转换为通过将 core.autocrlf 设置为 LF 提交而不是相反输入:

If you’re on a Linux or Mac system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

$ git config --global core.autocrlf input

此设置应该让您在 Windows 结帐中使用 CRLF 结尾,但 LF 在 Mac 和 Linux 系统以及存储库中结束.

This setup should leave you with CRLF endings in Windows checkouts, but LF endings on Mac and Linux systems and in the repository.

如果你是一名 Windows 程序员,正在做一个仅限 Windows 的项目,那么你可以关闭这个功能,记录回车通过将配置值设置为 false 来存储存储库:

If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:

$ git config --global core.autocrlf false

这篇关于LF 将被 git 中的 CRLF 取代 - 那是什么,它很重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆