bash SVN:“不一致的行结束样式”- 故意用 ^M 签入文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1528221/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:15:38  来源:igfitidea点击:

SVN: "Inconsistent line ending style" - Checking in a file with ^M intentionally

svnbash

提问by Chuck Wolber

Using svn version 1.3.1 (unable to upgrade due to a configuration controlled CM server) on CentOS 4.2.

在 CentOS 4.2 上使用 svn 版本 1.3.1(由于配置控制的 CM 服务器而无法升级)。

My code (a bash script) specifically has a ^M in it for an important reason. Unfortunately, subversion will not let me check this file in. It complains that:

出于一个重要原因,我的代码(一个 bash 脚本)特别包含一个 ^M。不幸的是,subversion 不允许我检入这个文件。它抱怨说:

svn: Commit failed (details follow):
svn: Inconsistent line ending style
svn: Your commit message was left in a temporary file:

svn:提交失败(详细信息如下):
svn:不一致的行结束样式
svn:您的提交消息留在临时文件中:

I have proven that removing the single ^M from my code allows it to be checked in. How do I tell subversion that the ^M is intentional and that it should allow the file to be checked in?

我已经证明从我的代码中删除单个 ^M 允许它被检入。我如何告诉 subversion ^M ​​是故意的并且它应该允许文件被检入?

回答by Wim Coenen

You need to remove the svn:eol-style propertyfrom your file. Subversion didn't care about line endings in your file until this property was added. To quote the subversion book:

您需要从文件中删除 svn:eol-style 属性。在添加此属性之前,Subversion 并不关心文件中的行尾。引用颠覆书

This means that by default, Subversion doesn't pay any attention to the type of end-of-line (EOL) markers used in your files.

这意味着默认情况下,Subversion 不会注意文件中使用的行尾 (EOL) 标记的类型。

The book then goes on describing how you can make subversion care about the line endings by setting the svn:eol-style, which is exactly what you don'twant.

然后这本书继续描述如何通过设置 使颠覆关心行尾svn:eol-style,这正是你想要的。

回答by DigitalRoss

Another approach would be to get rid of the control character in the program in the first place; this might have other compatibility benefits, and might avoid problems with editing in the future.

另一种方法是首先去掉程序中的控制字符;这可能具有其他兼容性优势,并可能避免将来出现编辑问题。

You can generate a \rin bash easily with

您可以使用以下命令\r轻松生成in bash

`printf '%b' '5'`

So, for example:

因此,例如:

$ echo abc`printf %b '5'`def
def
$ 

Or:

或者:

$ c=`printf %b '5'`
$ set | grep ^c=
c=$'\r'
$ 

(Note:I know there are easier ways than by calling printf. Unfortunately, those easier ways are different in bash and posix shells. A bash-only solution is quite nice: $'\r'. Ash-only even nicer: c='\r. I'm not sure if ashdoes this because it's ash or because it's posix.)

注意:我知道有比调用 printf 更简单的方法。不幸的是,这些更简单的方法在 bash 和 posix shell 中是不同的。仅 bash 的解决方案非常好:$'\r'.仅灰更好:c='\r。我不确定是否ash这样做是因为它是灰烬或因为它是 posix。)

回答by Spencer Ruport

I'm assuming it's being used as a string or something. Doesn't bash have a way to encode characters?

我假设它被用作字符串或其他东西。bash 没有编码字符的方法吗?

回答by JesperE

I think you need to use the svn:eol-styleproperty:

我认为您需要使用该svn:eol-style属性:

svn propset svn:eol-style LF myscript.sh

will cause Subversion to always treat the file as having LF-style line-endings.

将导致 Subversion 始终将文件视为具有 LF 样式的行尾。

回答by developmentalinsanity

I think you can set the svn:mime-type property to something none-text based (like application/octet-stream ?). This might make subversion ignore the line endings.

我认为您可以将 svn:mime-type 属性设置为基于非文本的内容(例如 application/octet-stream ?)。这可能会使 subversion 忽略行尾。

Have a look at the File Content Typesection of the svnbook.

查看svnbook的文件内容类型部分。