LF将由git中的CRLF替换-那是什么,它很重要吗? [重复]

本文翻译自:LF will be replaced by CRLF in git - What is that and is it important? [duplicate]

Possible Duplicate: 可能重复:
git replacing LF with CRLF git用CRLF替换LF

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楼

参考:https://stackoom.com/question/OTh0/LF将由git中的CRLF替换-那是什么-它很重要吗-重复


#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, read the documentation 如果您想做出明智的决定,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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值