博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LF将由git中的CRLF替换-那是什么,它很重要吗? [重复]
阅读量:2291 次
发布时间:2019-05-09

本文共 5069 字,大约阅读时间需要 16 分钟。

本文翻译自:

Possible Duplicate: 可能重复:

When I create a new rails application I'm seeing a warning in git about LF replacement. 当我创建一个新的Rails应用程序时,我在git中看到有关LF替换的警告。 I do git init git add . 我做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. 我通常只是继续构建我的应用程序,在对文件进行许多更改后它消失了。

Example: 例:

The file will have its original line endings in your working directory. 该文件将在您的工作目录中具有其原始行结尾。 warning: LF will be replaced by CRLF in Gemfile. 警告:在Gemfile中,LF将被CRLF替换。

The file will have its original line endings in your working directory. 该文件将在您的工作目录中具有其原始行结尾。 warning: LF will be replaced by CRLF in Gemfile.lock. 警告:LF将被Gemfile.lock中的CRLF替换。

The file will have its original line endings in your working directory. 该文件将在您的工作目录中具有其原始行结尾。 warning: LF will be replaced by CRLF in README. 警告:README中的LF将被CRLF替换。

What's the difference between LF and CRLF? LF和CRLF有什么区别?

Should I be concerned about this in the long run or just ignore it and keep going as I usually do? 从长远来看,我应该担心这个问题还是只是忽略它并像往常一样继续前进?


#1楼

参考:


#2楼

In Unix systems the end of a line is represented with a line feed (LF). 在Unix系统中,行尾用换行(LF)表示。 In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). 在窗口中,用回车(CR)和换行(LF)(CRLF)表示一行。 when you get code from git that was uploaded from a unix system they will only have an LF. 当您从unix系统上载的git中获取代码时,它们将只有LF。

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 如果您是在Windows机器上工作的单个开发人员,并且不关心git自动将LF替换为CRLF,则可以通过在git命令行中键入以下内容来关闭此警告

git config core.autocrlf true

If you want to make an intelligent decision how git should handle this, 如果您想做出明智的决定,git应该如何处理,

Here is a snippet 这是一个片段

Formatting and Whitespace 格式和空格

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. 补丁程序或其他协作工作很容易引入细微的空格变化,因为编辑者会默默地引入它们,并且如果您的文件曾经接触过Windows系统,则它们的行尾可能会被替换。 Git has a few configuration options to help with these issues. Git有一些配置选项可帮助解决这些问题。

core.autocrlf

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. 如果您在Windows上进行编程,并且与非Windows的人一起工作(反之亦然),则有时可能会遇到行尾问题。 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. 这是因为Windows在其文件中的换行符中使用了回车符和换行符,而Mac和Linux系统仅使用了换行符。 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. Windows上的许多编辑器都以CRLF静默替换现有的LF样式的行尾,或者在用户按下Enter键时插入两个行尾字符。

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. 当您将文件添加到索引时,Git可以通过将CRLF行尾自动转换为LF来解决此问题,反之亦然,当它将代码签出到文件系统中时,反之亦然。 You can turn on this functionality with the core.autocrlf setting. 您可以使用core.autocrlf设置启用此功能。 If you're on a Windows machine, set it to true – this converts LF endings into CRLF when you check out code: 如果您使用的是Windows计算机,请将其设置为true –在签出代码时,这会将LF结尾转换为CRLF:

$ git config --global core.autocrlf true

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; 如果您使用的是使用LF行尾的Linux或Mac系统,那么您不希望Git在签出文件时自动将它们转换; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. 但是,如果意外引入了带有CRLF结尾的文件,则您可能需要Git对其进行修复。 You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input: 您可以通过将core.autocrlf设置为input来告诉Git在提交时将CRLF转换为LF,反之则不行:

$ git config --global core.autocrlf input

This setup should leave you with CRLF endings in Windows checkouts, but LF endings on Mac and Linux systems and in the repository. 此设置应使您在Windows检出中具有CRLF结尾,但在Mac和Linux系统以及存储库中具有LF结尾。

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: 如果您是Windows程序员,并且仅在Windows上执行项目,则可以关闭此功能,通过将config值设置为false来在存储库中记录回车:

$ git config --global core.autocrlf false

#3楼

If you want, you can deactivate this feature in your git core config using 如果需要,您可以使用以下命令在git core配置中停用此功能

git config core.autocrlf false

But it would be better to just get rid of the warnings using 但是最好使用以下方法消除警告

git config core.autocrlf true

转载地址:http://abcnb.baihongyu.com/

你可能感兴趣的文章
网站访问速度一般检查参数
查看>>
编译安装过程
查看>>
HTTP常见返回码信息
查看>>
WEB集群session处理方案
查看>>
JDK命令行(jps、jstat、jinfo、jmap、jhat、jstack、jstatd、hprof)与JConsole
查看>>
JAVA 对象访问: 句柄和指针
查看>>
秒杀系统优化思路
查看>>
dubbo 报错:java.lang.NoClassDefFoundError: org/I0Itec/zkclient/exception/ZkNoNodeException
查看>>
logback的使用和logback.xml详解
查看>>
Linux 快捷键
查看>>
JPA 联合主键配置
查看>>
ObjectAlreadyExistsException:Unable to store Job : '*', because one already exists with thi s ident
查看>>
mybatis & JPA 实体类型属性转换
查看>>
Git 中的 ~ 和 ^
查看>>
第一篇博客,给大家分享java、架构师、大数据、人工智能的学习路线,希望能够帮助到大家
查看>>
18级大数据专家,跟大家漫谈大数据平台架构,你能学到多少?上篇
查看>>
18级大数据专家,漫谈大数据平台安全风险与建设,值得学(下篇)
查看>>
阿里P8终于整理出:Nginx+jvm+MySQL+Docker+Spring实战技术文档
查看>>
腾讯T4专家精心整理:大数据+机器学习+数据挖掘+算法大集结
查看>>
阿里P8终于总结出:SpringBoot+Tomcat+Nginx+Netty面试题及答案
查看>>