windows 尝试提交 Git 文件但得到 :: fatal: LF 将被替换为 <repo 中的某个文件> 中的 CRLF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15467507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to commit Git files but getting :: fatal: LF would be replaced by CRLF in <some file in repo>
提问by Pure.Krome
When I try to commit some changed files, I get the following error message with TortoiseGit
当我尝试提交一些更改的文件时,我收到以下 TortoiseGit 错误消息
fatal: LF would be replaced by CRLF in <some file in the repo>
fatal: LF would be replaced by CRLF in <some file in the repo>
Now, before I get the usual LF vs CRLF
answers, I know and understand what the debate is about. Secondly, I've also set my global settings to:
现在,在我得到通常的LF vs CRLF
答案之前,我知道并理解辩论的内容。其次,我还将全局设置设置为:
core.autocrlf true
core.autocrlf true
Third, I've got a .gitattributes
file.
So I -want- to make sure or files are forced to have CRLF
.
所以我 - 想要 - 确保或文件被迫具有CRLF
.
What I don't understand is that it's saying FATAL
and blocking me from continuing. A Warning? Sure! Do I know what I'm trying to do? I do!
我不明白的是它在说FATAL
并阻止我继续。一个警告?当然!我知道我要做什么吗?我愿意!
I just want it to convert silently and STFU.
我只是想让它默默地转换和 STFU。
Alternatively, if it's forced to BLOCK me, is there a way I can update all files in the repo to be CRLF
, so this warning is no longer issued?
或者,如果它被迫阻止我,有没有办法可以将 repo 中的所有文件更新为CRLF
,因此不再发出此警告?
These repos are private, so they will never be developed outside of Windows + Visual Studio.
这些存储库是私有的,因此它们永远不会在 Windows + Visual Studio 之外开发。
How can I proceed?
我该如何继续?
回答by VonC
You might want to set core.safecrlf
to "warn", if you want only warning and not a fatal error.
core.safecrlf
如果您只想要警告而不是致命错误,您可能希望设置为“警告”。
From "git config
" mange page:
core.safecrlf
core.safecrlf
If true, makes git check if converting CRLF is reversible when end-of-line conversion is active. Git will verify if a command modifies a file in the work tree either directly or indirectly.
For example, committing a file followed by checking out the same file should yield the original file in the work tree. If this is not the case for the current setting of core.autocrlf, git will reject the file.
The variable can be set to "warn", in which case git will only warn about an irreversible conversion but continue the operation.CRLF conversion bears a slight chance of corrupting data.
When it is enabled, git will convert CRLF to LF during commit and LF to CRLF during checkout.
A file that contains a mixture of LF and CRLF before the commit cannot be recreated by git.
For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the conversion can corrupt data.If you recognize such corruption early you can easily fix it by setting the conversion type explicitly in
.gitattributes
.
Right after committing you still have the original file in your work tree and this file is not yet corrupted. You can explicitly tell git that this file is binary and git will handle the file appropriately.Unfortunately, the desired effect of cleaning up text files with mixed line endings and the undesired effect of corrupting binary files cannot be distinguished.
In both cases CRLFs are removed in an irreversible way. For text files this is the right thing to do because CRLFs are line endings, while for binary files converting CRLFs corrupts data.
如果为 true,当行尾转换处于活动状态时,让 git 检查转换 CRLF 是否可逆。Git 将验证命令是否直接或间接修改了工作树中的文件。
例如,提交一个文件然后检出同一个文件应该会在工作树中产生原始文件。如果 core.autocrlf 的当前设置不是这种情况,git 将拒绝该文件。
该变量可以设置为“warn”,在这种情况下,git 只会对不可逆转的转换发出警告,但会继续操作。CRLF 转换可能会损坏数据。
启用后,git 将在提交期间将 CRLF 转换为 LF,在结帐期间将 LF 转换为 CRLF。
git 无法重新创建在提交之前包含 LF 和 CRLF 混合的文件。
对于文本文件,这是正确的做法:它会更正行尾,以便我们在存储库中只有 LF 行尾。
但是对于意外分类为文本的二进制文件,转换可能会损坏数据。如果您及早发现此类损坏,您可以通过在
.gitattributes
.
提交后,您的工作树中仍然有原始文件,并且该文件尚未损坏。你可以明确地告诉 git 这个文件是二进制的,git 会适当地处理这个文件。不幸的是,无法区分清理具有混合行尾的文本文件的预期效果和损坏二进制文件的不良效果。
在这两种情况下,CRLF 都以不可逆的方式删除。对于文本文件,这是正确的做法,因为 CRLF 是行尾,而对于二进制文件,转换 CRLF 会损坏数据。
I prefer identifying the exact files or types of file I want to force the eol with .gitattributes
files only (with core.eol
settings, which you have), and leave autocrlf
to false.
我更喜欢确定我想.gitattributes
仅使用文件(使用core.eol
您拥有的设置)强制 eol 的确切文件或文件类型,并保留autocrlf
为 false。
In case of text fiels with mixed eol, this blog postsuggests, for instance, to:
对于混合 eol 的文本字段,此博客文章建议例如:
If you have Notepad++ installed in your computer, simply follow these steps.
- Open the file that is having the Fatal issue.
- Click
Edit -> EOL Conversion
then select Windows Format or to any that you're having an issue committing.
如果您的计算机中安装了 Notepad++,只需按照以下步骤操作即可。
- 打开存在致命问题的文件。
- 单击
Edit -> EOL Conversion
然后选择 Windows 格式或您在提交时遇到问题的任何格式。
Warning, if you have Git 2.17 or 2.18: a regression introduced in 8462ff4("convert_to_git()
: safe_crlf/checksafe
becomes int conv_flags
", 2018-01-13, Git 2.17.0) back in Git 2.17 cycle caused autocrlf
rewrites to produce a warning message despite setting safecrlf=false
.
警告,如果您有 Git 2.17 或 2.18:在8462ff4(“ convert_to_git()
:safe_crlf/checksafe
变成int conv_flags
”,2018-01-13,Git 2.17.0)中引入的回归在 Git 2.17 周期中导致autocrlf
重写,尽管设置了safecrlf=false
.
See commit 6cb0912(04 Jun 2018) by Anthony Sottile (asottile
).
(Merged by Junio C Hamano -- gitster
--in commit 8063ff9, 28 Jun 2018)
请参阅Anthony Sottile( )提交的 6cb0912(2018 年 6 月 4 日)。(由Junio C Hamano合并-- --在8063ff9 提交中,2018 年 6 月 28 日)asottile
gitster
回答by Snowcrash
git config --global core.safecrlf false
回答by sanjeet bisht
This will disable the crlf fatal warning.
这将禁用 crlf 致命警告。
git config core.autocrlf false
git config core.safecrlf false
回答by Wade
Since your repo is private, you can set git-config
like this:
由于您的回购是私有的,您可以这样设置git-config
:
git config --global core.autocrlf false
git config --global core.autocrlf false
This will solve your problem.If you have any further question, You can read the 《Pro git》:
这将解决您的问题。如果您有任何进一步的问题,您可以阅读《Pro git》:
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:
$ git config --global core.autocrlf false
如果你是一个 Windows 程序员,正在做一个仅限 Windows 的项目,那么你可以关闭这个功能,通过将 config 值设置为false来在存储库中记录回车:
$ git config --global core.autocrlf false
But when collaborating, you should better do these below:
但是在协作时,您最好执行以下操作:
- add
.gitattributes
, Github help-Dealing with line endingswill be helpful. git config --global core.safecrlf true
- windows:
git config --global core.autocrlf true
- mac or linux:
git config --global core.autocrlf input
- windows:
- 添加
.gitattributes
,Github 帮助-处理行尾会有所帮助。 git config --global core.safecrlf true
- 视窗:
git config --global core.autocrlf true
- mac 或 linux:
git config --global core.autocrlf input
- 视窗:
You may want to Read Git docs-git configfor more info.
您可能需要阅读Git docs-git config以获取更多信息。
回答by Grigory Kislin
git config --global core.autocrlf false
will checkin files with CRLF, that is not used to.
git config --global core.autocrlf false
将使用 CRLF 签入文件,这是不习惯的。
I've noticed on Windows, that with core.autocrlf true
git doesn't like files with LF and core.autocrlf input
doesn't like CRLF.
我注意到在 Windows 上,core.autocrlf true
git 不喜欢带有 LF 的文件,core.autocrlf input
也不喜欢 CRLF。
So: commit CRLF files with core.autocrlf true
and LF files with core.autocrlf input
(or convert them to CRLF).
所以:提交 CRLF 文件core.autocrlf true
和 LF 文件core.autocrlf input
(或将它们转换为 CRLF)。
Usually files with LF is autogenerated by code generators (e.g. https://start.spring.ioor http://yeoman.io/)
通常带有 LF 的文件由代码生成器自动生成(例如https://start.spring.io或http://yeoman.io/)
回答by MyGeertRo
With .gitattributes file, use
使用 .gitattributes 文件,使用
*.h text=auto
*.cpp text=auto
*.txt text=auto
as is documented in https://git-scm.com/docs/gitattributes.