本文介绍了Windows git“警告:LF将被CRLF替换”,是否向后警告尾部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Windows 7 msysgit 当我 git commit 时,它说: 警告:LF将被CRLF取代。 这是警告尾部向后吗? 我在Windows中编辑文件,结尾的线是 CRLF ,就像这张图: 然后git将它改变为 LF 来提交回购。 所以我认为正确的警告是: 警告:CRLF将被LF取代。 解决方案 根据您使用的编辑器,带有LF的文本文件不需要使用CRLF保存:最近编辑者可以保留 eol风格。但是,该git配置设置坚持改变这些... 只要确保(如 git config --global core.autocrlf false 这样可以避免任何自动转换,并且仍然可以通过 .gitattributes 文件和 core.eol 指令。 否:您使用的是Windows,而 git config 帮助页面提及 正如 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 上,只有当所述提交是合并过程的一部分时。 注意:使用Git 2.17(Q2 2018),代码清理会添加一些解释。 commit 8462ff4 (2018年1月13日) TorstenBögershausen( tboegi )。 (由 Junio C Hamano - gitster - 在 commit 9bc89b1 ,2018年2月13日) SAFE_CRLF_FALSE:在发生EOL往返错误时不做任何操作 SAFE_CRLF_FAIL:die如果发生EOL往返错误 SAFE_CRLF_WARN:在发生EOL往返错误时发出警告 SAFE_CRLF_RENORMALIZE:将CRLF更改为LF SAFE_CRLF_KEEP_CRLF:将所有行结束保留为 env:Windows 7msysgitWheng 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. 解决方案 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 falseThat way, you avoid any automatic transformation, and can still specify them through a .gitattributes file and core.eol directives.No: you are on Windows, and the git config help page does mentionAs 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: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)SAFE_CRLF_FALSE: do nothing in case of EOL roundtrip errorsSAFE_CRLF_FAIL: die in case of EOL roundtrip errorsSAFE_CRLF_WARN: print a warning in case of EOL roundtrip errorsSAFE_CRLF_RENORMALIZE: change CRLF to LFSAFE_CRLF_KEEP_CRLF: keep all line endings as they are 这篇关于Windows git“警告:LF将被CRLF替换”,是否向后警告尾部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 19:55