VSCODE警告:LF将被CRLF取代

发布于 2025-02-06 20:15:27 字数 310 浏览 0 评论 0 原文

在VScode中,我有一个弹出窗口说:

warning: LF will be replaced by CRLF in <xxx>

我认为这是一个警告,但我的提议没有通过。

我检查并尝试找到一个在VSCODE内部配置Git的地方。我阅读了一些建议:

git config --get core.autocrlf 

我尝试在VSCODE设置中找到一些选项,但是我只是找不到在VSCODE中配置此选项。

配置此方法的正确方法是什么?非常感谢。

In VSCode, I have this pop-up that says:

warning: LF will be replaced by CRLF in <xxx>

I thought it's a warning but my commit didn't go through.

I check and try to find a place to configure GIT inside VSCode. I read some advice like:

git config --get core.autocrlf 

I try to find some options in VSCode settings, but I just could not find a way to configure this in VSCode.

What's the correct way to configure this ? Thanks very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅语花开 2025-02-13 20:15:27

外部VSCODE, git config -global core.autocrlf false 是一个不错的选择,因为i a>。

在VSCODE内部,请确保EOL(线的末端)指示器(状态栏中的右下角)是右一个。
如果您的文件具有混合行结尾,则没有选项可以选择退出文件限制文件,意思是,保存使用VS代码编辑的文件后,它似乎会自动执行限制范围,并且没有任何形式的用户通知。

注意:警告消息随

In the working copy of 'hello.txt', LF will be replaced by CRLF 
the next time Git touches it.

Outside VSCode, git config --global core.autocrlf false is a good option, as I mentioned here.

Inside VSCode, make sure the EOL (end of line) indicator (bottom right corner in the status bar) is the right one.
If your file has mixed line ending, there is no option to opt out of line ending normalisation for files, meaning, upon saving a file edited with VS Code, it appears to perform line ending normalisation automatically and without user notification of any sort.

Note: the warning message changes with Git 2.37 (Q3 2022) and becomes:

In the working copy of 'hello.txt', LF will be replaced by CRLF 
the next time Git touches it.
遮云壑 2025-02-13 20:15:27

如果您在Windows上工作,则需要确定所需的线条结尾,以及在存储库中想要的线结尾。 autocrlf 设置的“正确”选择对每个人来说都不一样。

afocrlf = false:不要弄乱我的文件!

@vonc的答案是正确的答案,如果您只是不想让git弄乱行结尾 - autocrlf 将设置为 false 意味着将文件输入和从git verbatim中。

可以说,这是 aforocrlf 的唯一正确设置,因为正如@vonc所指出的那样,诸如Windows .bat文件之类的文件将被NewLine转换打破,并且您确实不希望线端端端转换发生在 lf转换,因此可能无法恢复.jpg文件

...

二进制文件要么(一旦您不小心完成了CRLF-&gt ; 但是:在我的存储库中,我总是想要Unix风格的新线。但是在我的Windows计算机上,许多讨厌的工具使用Windows风格的新线创建文件。是的,您可以(并且应该)将编辑器设置为使用正确的行末尾,但是 Autocrlf 将设置为 input 捕获我的“错误”,例如,当文件为时由Windows计算机上的Python脚本生成,通常以CRLF线路结尾产生。在我的Windows配置中,我始终使用 git config --lobal core.autocrlf输入,这意味着我的文件始终使用Unix样式的newlines致力,但是当它们存在于存储库中时,它们会被签出。

.bat和二进制文件呢?当此设置引起转换时,git向我发出警告,因此,如果要在不应该​​的文件上发生,我会得到警告,并可以解决该提交的情况。但是,我不记得曾经对此有问题,但是我的git存储库几乎是我真正想要LF结尾的便携式源代码和文本文件。

我认为,如果您正在从Windows PC上处理以Linux或Mac为导向的项目,这是一个不错的设置。

afocrlf = true:我真的总是希望在退房文件中

我提到的文件中的CRLF以使其完整,但通常会建议您。如果您始终希望使用CRLF线路结束时的文件,则将 afocrlf 设置为 true 会做到这一点,但会在Unix-style style lf lf行末尾提交它们。在某些情况下,这是有道理的,但是在许多情况下可能会引起麻烦。

全球保存

做出您的选择并在您收到的消息中 ,我猜 true 是您的设置,因此您可能要确定 false 输入的哪个最适合您,并通过在git bash提示中运行这两个命令之一:

git config --global core.autocrlf false

git config --global core.autocrlf input

git开发人员的愿望列表:

我真正想要的是 autocrlf = stright 设置:询问我在尝试使用CRLF提交文件时该怎么办。我想我应该为此做一个预先承诺的钩子...

If you're working on Windows, you need to decide what line endings you want in your sandbox, and what line endings you want in your repos. The "right" choice for the autocrlf setting is not the same for everyone.

autocrlf=false: don't mess with my files!

@VonC's answer is the right answer if you just don't want Git to mess with line endings - an autocrlf set to false means take files in and out of Git verbatim.

This is arguably the only correct setting for autocrlf, because as @VonC pointed out, files like Windows .bat files will get broken by newline conversions, and you really do not want line-end conversions to happen in binary files either (that .jpg file might not be recoverable once you've accidentally done a CRLF->LF conversion on it...)

autocrlf=input: fix my mistakes when I create files

My usual answer on Windows is different, however: in my repos, I want Unix-style newlines, always. But on my Windows machine a number of pesky tools create files with Windows-style newlines. Yes, you can (and should) set your editor to use the right line endings, but an autocrlf set to input catches my "mistakes", e.g., when a file is generated by a Python script on a Windows machine, it usually ends up with CRLF line endings. In my Windows configurations, I always use git config --global core.autocrlf input, and that means my files always get committed with Unix style newlines, but they get checked out as they exist in the repo.

What about .bat and binary files? When this settings causes a conversion, Git issues a warning for me, so if it were to happen on a file where it should not, I'd get a warning and could fix the situation for that commit. I don't remember ever having had a problem with this, however, but my Git repos are pretty much exclusively portable source code and text files where I really, really want LF endings.

I think this is a nice setting if you're working on a Linux- or Mac-oriented project from a Windows PC.

autocrlf=true: I really always want CRLF in my checked out files

I mention this one for completeness, but would generally advise against it. If you always want your files with CRLF line endings when you're working on them, setting autocrlf to true will do that, but commit them in Unix-style LF line endings. This makes sense in some cases, but it can cause trouble in many cases.

Make your choice and save it globally

From the message you got, I'm guessing true was your setting, so you probably want to decide which of false or input is best for you, and set that globally, by running one of these two commands in your Git Bash prompt:

git config --global core.autocrlf false

or

git config --global core.autocrlf input

Wish-list for Git developers:

What I would really like is an autocrlf=prompt setting: ask me what to do any time I try to commit a file with a CRLF in it. I guess I should make myself a pre-commit hook for it...

独木成林 2025-02-13 20:15:27

如果您正在使用Windows
修复是通过使用autocrlf true

git config -lobal core.autocrlf true

除非您再次删除并克隆回购或重新启动索引

git添加 - 纯正。

If you're using Windows
The fix is by using autocrlf true

git config --global core.autocrlf true

You won’t see it work unless you delete and clone the repos again or restart the index by

git add --renormalize .

故乡的云 2025-02-13 20:15:27

在VS代码中,您将在屏幕右下角看到线的末端(EOL)指示器,显示“ LF”。单击它,选择将在屏幕顶部弹出(您选择解释器等),您可以如本网站上所述更改该值: https://dev.to/wagslane/how-to-to-get-consistent-line-line-breaks-in-vs-code-code-code-lf-vs-crlf-2c3p#:text = the %% 20quick%20fix&amp; text = at%20%20bottom%20 right%20OF,具有%20%the%20级百分比20line%20 breaks。。。

In VS Code, you will see an End of Line (EOL) indicator in the bottom right of your screen that shows "LF". Click on it and a selection will pop up in the top of the screen (where you select interpreter, etc), and you can change the value there as described on this site: https://dev.to/wagslane/how-to-get-consistent-line-breaks-in-vs-code-lf-vs-crlf-2c3p#:~:text=The%20Quick%20Fix&text=At%20the%20bottom%20right%20of,has%20the%20correct%20line%20breaks..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文