Windows git“警告:LF将被CRLF替换”,是否向后警告尾部? [英] Windows git "warning: LF will be replaced by CRLF", is that warning tail backward?

查看:442
本文介绍了Windows git“警告:LF将被CRLF替换”,是否向后警告尾部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • Windows 7

  • msysgit



当我 git commit 时,它说:

 警告:LF将被CRLF取代。 

这是警告尾部向后吗?

我在Windows中编辑文件,结尾的线是 CRLF ,就像这张图:



然后git将它改变为 LF 来提交回购。

所以我认为正确的警告是:

 警告:CRLF将被LF取代。 


解决方案


警告:由CRLF取代。

根据您使用的编辑器,带有LF的文本文件不需要使用CRLF保存:最近编辑者可以保留 eol风格。但是,该git配置设置坚持改变这些...



只要确保(如

  git config --global core.autocrlf false 

这样可以避免任何自动转换,并且仍然可以通过 .gitattributes 文件 core.eol 指令





windows gitLF将被CRLF替换

这个警告尾部向后?

否:您使用的是Windows,而 git config 帮助页面提及


如果您希望 CRLF 结束行即使存储库没有规范化的行结尾,也可以在你的工作目录中找到它。 使用CRLF替换LF的git ,仅在结帐时发生(未提交), core .autocrlf = true 。

 回购
/ \
crlf- > lf lf-> crlf
/ \

正如小平回答,该警告与以下情况相同:


警告:(如果您检出/克隆到您当前<$ c $的其他文件夹c> core.autocrlf configuration,)LF将被CRLF替换为

该文件的原始行结束符将放在当前的工作目录中。







正如 quaylar comments ,if there是提交时的转换,它只是 LF



特定的警告 LF将被CRLF取代来自 convert.c#check_safe_crlf()

  if(checksafe == SAFE_CRLF_WARN)
warning (LF将由%s中的CRLF取代。
该文件的工作目录中的原始行结尾为
。,path);
else / * ie SAFE_CRLF_FAIL * /
die(LF将被CRLF in%s,path);

它由 convert.c#crlf_to_git() ,本身由 convert.c调用convert.c #convert_to_git() ,本身由 convert.c#renormalize_buffer()

最后 renormalize_buffer()仅由 merge-recursive.c#blob_unchanged()

所以我怀疑这个转换发生在 git commit 上,只有当所述提交是合并过程的一部分时。



< hr>

注意:使用Git 2.17(Q2 2018),代码清理会添加一些解释。 commit 8462ff4 (2018年1月13日) TorstenBögershausen( tboegi
(由 Junio C Hamano - gitster - commit 9bc89b1 ,2018年2月13日)


convert_to_git():safe_crlf / checksafe变为int conv_flags



当调用 convert_to_git()时, checksafe 参数定义了什么
如果EOL转换( CRLF - > LF - > CRLF )不干净
往返。

此外,它还定义了行结尾是否应该重新标准化( CRLF - > LF



checksafe是带有这些值的 safe_crlf enum :



  SAFE_CRLF_FALSE:在发生EOL往返错误时不做任何操作
SAFE_CRLF_FAIL:die如果发生EOL往返错误
SAFE_CRLF_WARN:在发生EOL往返错误时发出警告
SAFE_CRLF_RENORMALIZE:将CRLF更改为LF
SAFE_CRLF_KEEP_CRLF:将所有行结束保留为


env:

  • Windows 7
  • msysgit

Wheng I git commit, it says:

warning: LF will be replaced by CRLF. 

Is this warning tail backward?
I edit file in Windows, the end of line is CRLF, just like this pic:

And git changes it to LF for committing to repo.
So I think the correct warning is:

warning: CRLF will be replaced by LF. 

解决方案

warning: LF will be replaced by CRLF.

Depending on the editor you are using, a text file with LF wouldn't necessary be saved with CRLF: recent editors can preserve eol style. But that git config setting insists on changing those...

Simply make sure that (as I recommend here):

git config --global core.autocrlf false

That way, you avoid any automatic transformation, and can still specify them through a .gitattributes file and core.eol directives.


windows git "LF will be replaced by CRLF"
Is this warning tail backward?

No: you are on Windows, and the git config help page does mention

Use this setting if you want to have CRLF line endings in your working directory even though the repository does not have normalized line endings.

As described in "git replacing LF with CRLF", it should only occur on checkout (not commit), with core.autocrlf=true.

       repo
    /        \ 
crlf->lf    lf->crlf 
 /              \    

As mentioned in XiaoPeng's answer, that warning is the same as:

warning: (If you check it out/or clone to another folder with your current core.autocrlf configuration,) LF will be replaced by CRLF
The file will have its original line endings in your (current) working directory.


As quaylar rightly comments, if there is a conversion on commit, it is to LF only.

That specific warning "LF will be replaced by CRLF" comes from convert.c#check_safe_crlf():

if (checksafe == SAFE_CRLF_WARN)
  warning("LF will be replaced by CRLF in %s.
           The file will have its original line endings 
           in your working directory.", path);
else /* i.e. SAFE_CRLF_FAIL */
  die("LF would be replaced by CRLF in %s", path);

It is called by convert.c#crlf_to_git(), itself called by convert.c#convert_to_git(), itself called by convert.c#renormalize_buffer().

And that last renormalize_buffer() is only called by merge-recursive.c#blob_unchanged().

So I suspect this conversion happens on a git commit only if said commit is part of a merge process.


Note: with Git 2.17 (Q2 2018), a code cleanup adds some explanation.

See commit 8462ff4 (13 Jan 2018) by Torsten Bögershausen (tboegi).
(Merged by Junio C Hamano -- gitster -- in commit 9bc89b1, 13 Feb 2018)

convert_to_git(): safe_crlf/checksafe becomes int conv_flags

When calling convert_to_git(), the checksafe parameter defined what should happen if the EOL conversion (CRLF --> LF --> CRLF) does not roundtrip cleanly.
In addition, it also defined if line endings should be renormalized (CRLF --> LF) or kept as they are.

checksafe was an safe_crlf enum with these values:

SAFE_CRLF_FALSE:       do nothing in case of EOL roundtrip errors
SAFE_CRLF_FAIL:        die in case of EOL roundtrip errors
SAFE_CRLF_WARN:        print a warning in case of EOL roundtrip errors
SAFE_CRLF_RENORMALIZE: change CRLF to LF
SAFE_CRLF_KEEP_CRLF:   keep all line endings as they are

这篇关于Windows git“警告:LF将被CRLF替换”,是否向后警告尾部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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