visual-studio Visual Studio 规范化不一致的行尾是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/553548/
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
What does Visual Studio mean by normalize inconsistent line endings?
提问by MetaGuru
Visual Studio occasionally tells me:
Visual Studio 偶尔会告诉我:
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.
然后它给了我不同标准或其他东西的下拉菜单,例如 Windows、Mac、Unix 和几个 Unicode 标准。
What does this mean and what is going to happen if I click Yes?
这是什么意思,如果我点击会发生Yes什么?
采纳答案by Ken White
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\nand another ending with \ror \n; the first is the Windows line end pair, while the others are typically used for Mac or Linux files.
规范行尾只是确保所有行尾字符都是一致的。它防止一行\r\n以\ror结尾而另一行以or结尾\n;第一个是 Windows 行端对,而其他的通常用于 Mac 或 Linux 文件。
Since you're developing in Visual Studio, you'll obviously want to choose "Windows" from the drop down. :-)
由于您在 Visual Studio 中进行开发,因此您显然希望从下拉列表中选择“Windows”。:-)
回答by Alex Reitbort
Some lines end with \n.
有些行以\n.
Some other lines end with \r\n.
其他一些行以\r\n.
Visual Studio suggests you to make all lines end the same.
Visual Studio 建议您使所有行的结尾都相同。
回答by pankaj
If you are using Visual Studio 2012:
如果您使用的是 Visual Studio 2012:
Go to menu File→ Advanced Save Options→ select Line endingstype as Windows (CR LF).
转到菜单文件→高级保存选项→ 选择行尾类型为Windows (CR LF)。
回答by CodingYoshi
To turn the option ON/OFF, follow the steps below from menubar:
要打开/关闭该选项,请按照菜单栏中的以下步骤操作:
Tools→ Options→ Environment→ Documents→ Check for consistent line endings on load
工具→选项→环境→文档→在加载时检查一致的行尾
回答by monowerker
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:
用于行结尾的 ASCII 字符是:
CR, Carriage Return
LF, Line Feed
CR、回车
LF、换行
Windows = CRLF
Mac OS 9 or earlier = CR
Unix = LF
Windows = CRLF 
Mac OS 9 或更早版本 = CR 
Unix = LF
回答by Richard Ev
The Wikipedia newline articlemight 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.
不同的换行约定经常导致在不同类型系统之间传输的文本文件显示不正确。例如,源自 Unix 或 Apple Macintosh 系统的文件在 Microsoft Windows 上运行的某些程序中可能显示为单长行。相反,在 Unix 系统上查看源自 Windows 计算机的文件时,额外的 CR 可能显示为 ^M 或在每行的末尾或第二个换行符。
回答by ChrisW
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).
这意味着,例如,您的某些文本行以 a <Carriage Return><Linefeed>(Windows 标准)结尾,而某些文本行仅以 a <Linefeed>(Unix 标准)结尾。
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).
这不会对编译器产生任何影响(因为行尾仅算作空格),但它可能会对其他工具产生一些影响(例如版本控制系统上的“差异”)。
回答by Peter Y
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.
不仅仅是 Visual Studio……它是任何读取文件、编译器、链接器等的工具,必须能够处理它。
In general (for software development) we accept the multiplatform line ending issue, but let the version control software deal with it.
通常(对于软件开发)我们接受多平台行结束问题,但让版本控制软件处理它。
回答by Jay Shah
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.
当您从网络复制粘贴某些内容时,您可能会得到不一致的行尾。
为了解决这个问题,您可以使用 Visual Studio 扩展“Line Endings Unifier”,它可以在保存文件时自动使行尾保持一致。
回答by Jay Shah
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
Visual Studio 2008 有一个加载项,可以在保存文件时转换行尾格式。你可以在这里下载:http: //grebulon.com/software/stripem.php


