本文翻译自: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

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

  1. Git中CRLF与LF的转换

    1.换行符在不同的操作系统上的表示 首先要理解的一点是,对于不同的操作系统,对于换行符的表示是不一样的.也就是说当我们在编辑一个文件,在键盘上按下回车键的时候,对于不同的操作系统保存到文件中的换行符是 ...

  2. git 中使用git add . 命令时候报如下警warning: LF will be replaced by CRLF in …….

    git 中使用git add . 命令时候报如下警告 warning: LF will be replaced by CRLF in --. The file will have its origin ...

  3. 怎么解决Git中出现 “LF will be replaced by CRLF“ 警告

    Windows中使用CRLF标识一行的结束,而在Linux/UNIX系统中只使用LF标识一行的结束.CRLF即Carriage-Return Line-Feed的缩写.通常情况下,Git库不会自动修改 ...

  4. CRLF、LF、CR详解及在git中应用

    基本 CRLF: Carriage-Return Line-Feed的缩写,意思是回车换行,即\r\n; LF: Line-Feed的缩写,意思是换行,即\n; CR: Carriage-Return ...

  5. git配置中的CRLF、LF、CR

    基本 CRLF: Carriage-Return Line-Feed的缩写,意思是回车换行,即\r\n; LF: Line-Feed的缩写,意思是换行,即\n; CR: Carriage-Return ...

  6. Git - 什么是 CRLF 和 LF

    是什么? 每次按键盘上的 回车 按键时,会插入一个称为行结束符的不可见字符.不同操作系统处理行结束符的方式不同. CRLF:回车换行(carriage return/line feed) LF:换行( ...

  7. Git最好的CRLF(回车,换行)处理策略是什么?

    我尝试使用CRLF结束行提交文件,但失败了. 我花了整整一天的时间在我的Windows计算机上尝试不同的策略,几乎被迫停止尝试使用Git而是尝试使用Mercurial . 每个答案只能分享一个最佳实践 ...

  8. 从另一个分支在Git中创建一个分支

    我有两个分支: master和dev 我想从dev分支创建一个"功能分支". 目前在分支机构dev上,我执行以下操作: $ git checkout -b myfeature de ...

  9. 如何在Git中更改多次提交的作者和提交者名称以及电子邮件?

    我当时正在学校计算机上编写一个简单的脚本,然后将更改提交到Git(在笔驱动器中的一个回购中,该回购是从家里的计算机中克隆的). 经过几次提交后,我意识到我正在以root用户身份提交东西. 有什么办法可 ...

最新文章

  1. SQL基础学习总结:6(INSERT语句的相关使用方法)
  2. GDOI2018 总结
  3. python27.dll引起的appcrash_python27.dll错误代码126怎么解决
  4. 3.寄存器(内存访问)
  5. Android Gradle和Gradle插件区别
  6. linkerd mysql_linkerd ab部署测试
  7. 跨国际日期分界线的解决方法
  8. 如何分组Windows窗体单选按钮?
  9. Pytorch中RNN输出的h_n和output是什么
  10. 安全彻底的卸载工具App Cleaner Uninstaller for Mac
  11. 解决:android源码同步repo sync 时出现的fatal:duplicate path错误
  12. 统计学(贾俊平《第七版》) 导论部分
  13. 基于ssm框架实现的企业进销存管理系统【源码+数据库+毕设】
  14. pron网站制作遇到的问题
  15. 古城钟楼的微博报时是如何实现的?[科普贴]
  16. SSRS 锁定标题栏
  17. MSDC 4.3 接口规范(17)
  18. 史上最强灌水:奇葩的MEGA 精选 科学网薛宇老师
  19. 英文文献翻译的几款实用工具
  20. linux qt 获取u盘名称,QT windows平台下获取U盘 QComboBox显示U盘盘符

热门文章

  1. TCP服务器和客户端的链接例子(侧重点在注意关闭套接子,减少套接子的描述子)
  2. 很有趣的问题,Public继承和默认的集成
  3. 自定义最大高度的ViewGroup
  4. 第五周项目一-三角形类雏形(1)
  5. Android10.0应用进程创建过程以及Zygote的fork流程-[Android取经之路]
  6. 互联网思维-NO.1思维(2)
  7. 数据如何写入到HBase
  8. iOS 获取本地图片URL
  9. lodop打印不显示页码_CAD上明明有图,但是打印的时候不显示怎么办?原来要这样设置...
  10. oracle的乐观锁和悲观锁