草庐IT

git - Windows git "warning: LF will be replaced by CRLF",警告尾部向后吗?

coder 2023-06-22 原文

环境:

  • window 7
  • 管理系统

当我 git commit 时,它说:

warning: LF will be replaced by CRLF. 

这个警示尾部是不是反了?
我在Windows下编辑文件,行尾是CRLF,如下图:

git 将其更改为 LF 以提交 repo 协议(protocol)。
所以我认为正确的警告是:

warning: CRLF will be replaced by LF. 

最佳答案

warning: LF will be replaced by CRLF.

根据您使用的编辑器,带有 LF 的文本文件不必使用 CRLF 保存:最近的编辑器可以保留 eol 样式。但是那个 git 配置设置坚持要改变那些......

只需确保(如 I recommend here ):

git config --global core.autocrlf false

这样,您就可以避免任何自动转换,并且仍然可以通过 .gitattributes file 指定它们和 core.eol directives .


windows git "LF will be replaced by CRLF"

备注:the warning message has changed with Git 2.37 (Q3 2022)

Is this warning tail backward?

不:你在 Windows 上,git config help page确实提到

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.

如“git replacing LF with CRLF”中所述,它应该只发生在 checkout 时(不提交),core.autocrlf=true

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

XiaoPeng 中所述的 answer ,该警告与:

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.

git-for-windows/git issue 1242 中所述:

I still feel this message is confusing, the message could be extended to include a better explanation of the issue, for example: "LF will be replaced by CRLF in file.json after removing the file and checking it out again".

注意:Git 2.19(2018 年 9 月),当使用 core.autocrlf 时,伪造的“LF 将被 CRLF 取代”警告现在被抑制


作为quaylar没错comments ,如果提交时有转换,则仅转换为 LF

特定警告“LF 将被 CRLF 替换”来自 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);

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

最后一个 renormalize_buffer() 只被 merge-recursive.c#blob_unchanged() 调用.

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


注意:对于 Git 2.17(2018 年第 2 季度),代码清理增加了一些解释。

参见 commit 8462ff4 (2018 年 1 月 13 日)作者:Torsten Bögershausen (tboegi) .
(由 Junio C Hamano -- gitster -- merge 于 commit 9bc89b1 ,2018 年 2 月 13 日)

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

请注意 8462ff4 中引入的回归("convert_to_git(): safe_crlf/checksafe 变为 int conv_flags", 2018-01-13, Git 2.17.0) 回到 Git 2.17 循环导致 autocrlf 重写以生成警告信息 尽管设置了 safecrlf=false

参见 commit 6cb0912 (2018 年 6 月 4 日)作者:Anthony Sottile (asottile) .
(由 Junio C Hamano -- gitster -- merge 于 commit 8063ff9 ,2018 年 6 月 28 日)

关于git - Windows git "warning: LF will be replaced by CRLF",警告尾部向后吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17628305/

有关git - Windows git "warning: LF will be replaced by CRLF",警告尾部向后吗?的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby - 在院子里用@param 标签警告 - 2

    我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?

  5. ruby-on-rails - active_admin 目录中的常量警告重新声明 - 2

    我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA

  6. ruby-on-rails - 启动 Rails 服务器时 ImageMagick 的警告 - 2

    最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru

  7. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  8. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  9. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  10. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

随机推荐