Visual Studio 标准化不一致的行结尾是什么意思?

发布于 2024-07-14 05:44:24 字数 198 浏览 14 评论 0原文

Visual Studio 偶尔会告诉我:

以下文件中的行结尾不一致。 您想标准化行结尾吗?

然后它会向我提供不同标准或其他标准的下拉列表,例如 Windows、Mac、Unix 和一些 Unicode 标准。

这意味着什么以及如果我单击“是” 会发生什么?

Visual Studio occasionally tells me:

The line endings in the following files are not consistent. Do you want to normalize the line endings?

It then gives me a drop down with different standards or something, such as Windows, Mac, Unix, and a couple of Unicode ones.

What does this mean and what is going to happen if I click Yes?

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

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

发布评论

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

评论(12

土豪 2024-07-21 05:44:24

这通常意味着您的行以回车/换行对以外的其他内容结尾。 当您从网页复制并粘贴到代码编辑器时,通常会发生这种情况。

规范化行结尾只是确保所有行结尾字符一致。 它可以防止一行以 \r\n 结尾,而另一行以 \r\n 结尾; 第一个是 Windows 线路端对,而其他的通常用于 Mac 或 Linux 文件。

由于您是在 Visual Studio 中进行开发,因此您显然需要从下拉列表中选择“Windows”。 :-)

What that usually means is that you have lines ending with something other than a carriage return/line feed pair. It often happens when you copy and paste from a web page into the code editor.

Normalizing the line endings is just making sure that all of the line ending characters are consistent. It prevents one line from ending in \r\n and another ending with \r or \n; the first is the Windows line end pair, while the others are typically used for Mac or Linux files.

Since you're developing in Visual Studio, you'll obviously want to choose "Windows" from the drop down. :-)

再可℃爱ぅ一点好了 2024-07-21 05:44:24

有些行以 \n 结尾。

其他一些行以 \r\n 结尾。

Visual Studio 建议您使所有行的结尾相同。

Some lines end with \n.

Some other lines end with \r\n.

Visual Studio suggests you to make all lines end the same.

情愿 2024-07-21 05:44:24

如果您使用的是 Visual Studio 2012:

转到菜单文件高级保存选项 → 选择行结尾类型为Windows ( CR LF)

If you are using Visual Studio 2012:

Go to menu FileAdvanced Save Options → select Line endings type as Windows (CR LF).

花想c 2024-07-21 05:44:24

要打开/关闭该选项,请从菜单栏中执行以下步骤:

工具选项环境文档检查加载时行尾是否一致

To turn the option ON/OFF, follow the steps below from menu bar:

ToolsOptionsEnvironmentDocumentsCheck for consistent line endings on load

能怎样 2024-07-21 05:44:24

行结尾也称为换行符行结束符(EOL)换行符是控制字符或序列字符编码规范(例如 ASCII 或 EBCDIC)中的控制字符,用于表示一行文本的结束和新文本行的开始。 某些文本编辑器会在您按Enter 键时设置/实现此特殊字符。

回车换行字符是行尾 (EOL) 的 ASCII 表示形式。 它们将结束字符串的当前行,并开始新的一行。

但是,在操作系统级别,它们的处理方式有所不同:

  • 回车符(“CR”)(ASCII 13\0x0D,\r):将光标移动到开头行而不前进到下一行。 该字符在 Commodore 和早期 Macintosh 操作系统(Mac OS 9 及更早版本)中用作换行符。

  • 换行(“LF”)字符(ASCII 10\0x0A,\n):将光标向下移动到下一行,而不返回到行首。 该字符在基于 Unix 的系统(Linux、macOS X、Android 等)中用作换行符。

  • 回车换行(“CRLF”)字符(0x0D0A,\r\n):这实际上是两个 ASCII 字符,是 CR 和 LF 字符的组合。 它将光标向下移动到下一行和该行的开头。 该字符在大多数其他非 Unix 操作系统(包括 Microsoft Windows 和 Symbian OS)中用作换行符。

在 Visual Studio 中标准化不一致的行结尾意味着选择一种字符类型用于所有文件。 它可能是:

  • 回车换行(“CRLF”)字符
  • 换行(“LF”)字符
  • 回车(“CR”)字符

但是,您可以使用根目录中的 .gitattributes 文件以更好的方式进行设置,以避免将文件从一个操作系统移动到另一个操作系统时发生冲突。

只需在应用程序的根目录中创建一个名为 .gitattributes 的新文件:

touch .gitattributes

并在其中添加以下内容:

# Enforce Unix newlines
* text=auto eol=lf

这会强制使用 Unix 换行 行结束字符。

注意:如果这是一个已经存在的项目,只需运行此命令即可使用 .gitattributes 中指定的新定义的行结尾来更新应用程序的文件。

git rm --cached -r .
git reset --hard

就这样。

我希望这有帮助

Line endings also called newline, end of line (EOL) or line break is a control character or sequence of control characters in a character encoding specification (e.g. ASCII or EBCDIC) that is used to signify the end of a line of text and the start of a new one. Some text editors set/implement this special character when you press the Enter key.

The Carriage Return, Line Feed characters are ASCII representations for the end of a line (EOL). They will end the current line of a string, and start a new one.

However, at the operating system level, they are treated differently:

  • The Carriage Return ("CR") character (ASCII 13\0x0D, \r): Moves the cursor to the beginning of the line without advancing to the next line. This character is used as the new line character in Commodore and Early Macintosh operating systems (Mac OS 9 and earlier).

  • The Line Feed ("LF") character (ASCII 10\0x0A, \n): Moves the cursor down to the next line without returning to the beginning of the line. This character is used as the new line character in Unix based systems (Linux, macOS X, Android, etc).

  • The Carriage Return Line Feed ("CRLF") character (0x0D0A, \r\n): This is actually two ASCII characters and is a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line. This character is used as the new line character in most other non-Unix operating systems, including Microsoft Windows and Symbian OS.

Normalizing inconsistent line endings in Visual Studio means selecting one character type to be used for all your files. It could be:

  • The Carriage Return Line Feed ("CRLF") character
  • The Line Feed ("LF") character
  • The Carriage Return ("CR") character

However, you can set this in a better way using .gitattributes file in your root directory to avoid conflicts when you move your files from one Operating system to the other.

Simply create a new file called .gitattributes in the root directory of your application:

touch .gitattributes

And add the following in it:

# Enforce Unix newlines
* text=auto eol=lf

This enforces the Unix line feed line ending character.

Note: If this is an already existing project, simply run this command to update the files for the application using the newly defined line ending as specified in the .gitattributes.

git rm --cached -r .
git reset --hard

That's all.

I hope this helps

上课铃就是安魂曲 2024-07-21 05:44:24

您正在编辑的文件已使用某些不使用相同行结尾的其他编辑器进行过编辑,从而导致文件具有混合行结尾。

用于行结束的 ASCII 字符有:

CR、回车
LF、换行

窗口 = CRLF
Mac OS 9 或更早版本 = CR
Unix = LF

The file you are editing has been edited with some other editor that does not use the same line endings, resulting in a file with mixed line endings.

The ASCII characters in use for line endings are:

CR, Carriage Return
LF, Line Feed

Windows = CRLF
Mac OS 9 or earlier = CR
Unix = LF

指尖上的星空 2024-07-21 05:44:24

维基百科换行文章可能会帮助您。 以下是摘录:

不同的换行约定通常会导致文本文件之间传输
不同类型的系统显示不正确。 例如,源自以下位置的文件
Unix 或 Apple Macintosh 系统上运行的某些程序可能会显示为单行长行
微软Windows。 相反,当在 Windows 计算机上查看源自 Windows 计算机的文件时
Unix系统,额外的CR可能显示为^M或在每行的末尾或作为
第二行换行符。

The Wikipedia newline article might help you out. Here is an excerpt:

The different newline conventions often cause text files that have been transferred between
systems of different types to be displayed incorrectly. For example, files originating on
Unix or Apple Macintosh systems may appear as a single long line on some programs running on
Microsoft Windows. Conversely, when viewing a file originating from a Windows computer on a
Unix system, the extra CR may be displayed as ^M or at the end of each line or as a
second line break.

稍尽春風 2024-07-21 05:44:24

当您从网络复制粘贴某些内容时,您可能会得到不一致的行结尾。
为了解决这个问题,您可以使用 Visual Studio 扩展“行尾统一器”,它可以在保存文件时自动使行尾保持一致。

输入图像描述这里

When you copy paste something from web, you might get the inconsistent line endings.
In order to fix this, you can use Visual studio extension "Line Endings Unifier" which can make line ending consistent automatically while saving file.

enter image description here

卸妝后依然美 2024-07-21 05:44:24

这意味着,例如,某些文本行带有 (Windows 标准),而有些文本行仅以 结尾。(Unix 标准)。

如果您单击“是”,源文件中的行尾将被转换为具有相同的格式。

这不会对编译器产生任何影响(因为行尾仅算作空白),但可能会对其他工具产生一些影响(例如版本控制系统上的“差异”)。

It means that, for example, some of your lines of text with a <Carriage Return><Linefeed> (the Windows standard), and some end with just a <Linefeed> (the Unix standard).

If you click 'yes' these the end-of-lines in your source file will be converted to have all the same format.

This won't make any difference to the compiler (because end-of-lines count as mere whitespace), but it might make some difference to other tools (e.g. the 'diff' on your version control system).

千紇 2024-07-21 05:44:24

不仅仅是 Visual Studio...任何读取文件、编译器、链接器等的工具都必须能够处理它。

一般来说(对于软件开发)我们接受多平台行结束问题,但让版本控制软件处理它。

It's not just Visual Studio... It'd be any tools that read the files, compilers, linkers, etc. that would have to be able to handle it.

In general (for software development) we accept the multiplatform line ending issue, but let the version control software deal with it.

梦里南柯 2024-07-21 05:44:24

Visual Studio 2008 有一个加载项,可以在保存文件时转换行尾格式。 您可以在这里下载:http://grebulon.com/software/stripem.php

There'a an add-in for Visual Studio 2008 that converts the end of line format when a file is saved. You can download it here: http://grebulon.com/software/stripem.php

冷夜 2024-07-21 05:44:24

我在 VS 2019 中遇到了这个问题,并通过为 Windows 设置 LineBreak 配置来解决它,然后再为 Unix 设置。

工具> 选项> 保存时格式化> 设置> 换行符:Windows

I had this problem in VS 2019 and solved it by setting the LineBreak configuration for Windows, before it was set for Unix.

Tools > Options > Format on Save > Settings > LineBreak: Windows

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