关于svn:如何告诉Subversion将文件视为二进制文件?

关于svn:如何告诉Subversion将文件视为二进制文件?

How do I tell Subversion to treat a file as a binary file?

如何告诉Subversion(svn)将文件视为二进制文件?


可以使用以下方法手动将位于存储库中的文件标识为二进制文件:

1
svn propset svn:mime-type application/octet-stream <filename>

这通常不是必需的,因为Subversion会在首次添加文件时尝试确定该文件是否为二进制文件。如果Subversion在应将其视为二进制文件时将某个类型错误地标记为"文本",则可以配置Subversion的auto-props功能以使用非文本MIME类型自动标记该文件。不管文件上配置的属性如何,Subversion仍将文件以二进制格式存储在资源库中。

如果Subversion将MIME类型标识为"文本"类型,则它将启用某些在二进制文件上不可用的功能,例如svn diff和svn blame。它还允许自动的行尾转换,可以在逐个客户端的基础上进行配置。

有关更多信息,请参见Subversion如何处理二进制文件?


来自Subversion书籍的第367页

In the most general sense, Subversion handles binary files more gracefully than CVS does.
Because CVS uses RCS, it can only store successive full copies of a changing binary file.
Subversion, however, expresses differences between files using a binary differencing algorithm,
regardless of whether they contain textual or binary data. That means all files are
stored differentially (compressed) in the repository.

CVS users have to mark binary files with -kb flags to prevent data from being garbled (due
to keyword expansion and line-ending translations). They sometimes forget to do this.

Subversion takes the more paranoid route. First, it never performs any kind of keyword or
line-ending translation unless you explicitly ask it to do so (see the section called"Keyword
Substitution" and the section called"End-of-Line Character Sequences" for more details).
By default, Subversion treats all file data as literal byte strings, and files are always stored
in the repository in an untranslated state.

Second, Subversion maintains an internal notion of whether a file is"text" or"binary" data,
but this notion is only extant in the working copy. During an svn update, Subversion will
perform contextual merges on locally modified text files, but will not attempt to do so for
binary files.

To determine whether a contextual merge is possible, Subversion examines the
svn:mime-type property. If the file has no svn:mime-type property, or has a MIME
type that is textual (e.g., text/*), Subversion assumes it is text. Otherwise, Subversion
assumes the file is binary. Subversion also helps users by running a binary-detection algorithm
in the svn import and svn add commands. These commands will make a good
guess and then (possibly) set a binary svn:mime-type property on the file being added.
(If Subversion guesses wrong, the user can always remove or hand-edit the property.)

手动编辑将由

完成

1
svn propset svn:mime-type some/type filename.extension

基本上,您必须将mime类型设置为八位字节流:

1
svn propset svn:mime-type application/octet-stream <filename>

如果'svn add'猜出了错误的类型,并给您类似以下的错误:

1
2
svn: E200009: File 'qt/examples/dialogs/configdialog/images/config.webp' has inconsistent newlines
svn: E135000: Inconsistent line ending style

然后解决方法是添加不带属性的文件,然后在第二步中设置属性:

1
2
svn add --no-auto-props qt/examples/dialogs/configdialog/images/config.webp
svn propset svn:mime-type image/png qt/examples/dialogs/configdialog/images/config.webp

例如:

1
svn propset svn:mime-type image/png foo.webp

尽管Subversion尝试自动检测文件是否为二进制文件,但是您可以使用svn propset覆盖mime类型。
例如,svn propset svn:mime-type application/octet-stream example.txt。这将使您的文件充当字节的集合,而不是文本文件。另请参见有关文件可移植性的svn手册。


如果在Windows中使用Torvise svn,请右键单击该文件并转到属性。单击new并添加类型为svn:mime-type的新属性。对于put值:application / octet-stream


svn寻找一个mime类型的属性,如果它不存在,则猜测它是文本。您可以显式设置此属性,请参见http://svnbook.red-bean.com/en/1.5/svn.forcvs.binary-and-trans.html


根据Subversion常见问题解答,您可以使用svn propset将svn:mime-type属性更改为application / octet-stream


通常默认情况下会为您执行此操作,但是如果不是,则需要查看文件属性和属性集。


推荐阅读