LF将被git中的CRLF替换 - 该文件将具有其原始行结尾 [英] LF will be replaced by CRLF in git -the file will have its original line endings

查看:1160
本文介绍了LF将被git中的CRLF替换 - 该文件将具有其原始行结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这通常发生在Windows上,并且core.autocrlf设置为true,或者.gitattributes包含用于执行行结束标准化的指令。

结束标准化的工作方式(在Windows机器上)是当您提交文件时,git用LF替换每个CRLF,并且在签出文件时, git用CRLF替换每个LF。通常这对你来说都是透明的,你所看到的只是你工作目录中的CRLF。但是,如果你以某种方式在你的工作目录中创建一个只有LF的文件,这里会发生什么:


  1. 提交时,git将转换LF到LF,即什么都不做

  2. 检出时,git会将LF转换为CRLF

结果是,您最终只用LF创建一个文件,但从那时起,您始终会看到CRLF。这是git警告你的。

假设它是我们正在讨论的文本文件,您可以继续并忽略此警告。但是,如果它是一个二进制文件,这意味着git将尝试对其执行行标准化,这将破坏文件。在这种情况下,你需要检查你的.gitattributes文件,看看为什么会这样。


LF will be replaced by CRLF in git -the file will have its original line endings what does this mean?

解决方案

This usually happens when you are on Windows and either core.autocrlf is set to true, or the .gitattributes contains directives to perform line ending normalizations.

The way line ending normalization works (on a Windows machine) is that when you commit a file, git replaces every CRLF with a LF, and when you checkout a file, git replaces every LF with a CRLF. Normally this is all transparent to you, and all you ever see is CRLFs in your working directory. However, if you somehow create a file with just LFs in your working directory, here is what will happen:

  1. When committing, git will "convert" the LFs to LFs, i.e. do nothing
  2. When checking out, git will convert the LFs to CRLFs

The upshot is, you end up creating a file with just LFs, but from then on you always see CRLFs in it. That is what git is warning you about.

Assuming that it is a text file we are talking about, you can go ahead and ignore this warning. However, if it is a binary file, it means that git is going to attempt to do line normalizations on it, which will corrupt the file. In that case you need to check your .gitattributes file and see why this is happening.

这篇关于LF将被git中的CRLF替换 - 该文件将具有其原始行结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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