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

Svn

Svn Problem Overview


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

Svn Solutions


Solution 1 - Svn

It is possible to manually identify a file located within a repository as binary by using:

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

This is generally not necessary, as Subversion will attempt to determine whether a file is binary when the file is first added. If Subversion is incorrectly tagging a certain type as "text" when it should be treated as binary, it is possible to configure Subversion's auto-props feature to automatically tag that file with a non-text MIME type. Regardless of the properties configured on the file, Subversion still stores the file in a binary format within the repository.

If Subversion identifies the MIME type as a "text" type, it enables certain features which are not available on binary files, such as svn diff and svn blame. It also allows for automatic line ending conversion, which is configurable on a client-by-client basis.

For more information, see How does Subversion handle binary files?

Solution 2 - Svn

From page 367 of the Subversion book

> 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.)

Hand editing would be done by

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

Solution 3 - Svn

Basically, you have to set the mime type to octet-stream:

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

Solution 4 - Svn

If 'svn add' guesses the incorrect type and gives you an error like the following:

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

then the workaround is to add the file without properties and then set the properties in a second step:

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

Solution 5 - Svn

For example:

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

Solution 6 - Svn

Although Subversion tries to automatically detect whether a file is binary or not, you can override the mime-type using svn propset. For example, svn propset svn:mime-type application/octet-stream example.txt. This will make your file act as a collection of bytes rather than a text file. See also, the svn manual on File Portability.

Solution 7 - Svn

If using tortoise svn in Windows, right click on the file and go to properties. Click on new and add a new property of type svn:mime-type. For the value put: application/octet-stream

Solution 8 - Svn

As per the Subversion FAQ, you can use svn propset to change the svn:mime-type property to application/octet-stream

Solution 9 - Svn

svn looks for a mime-type property, guessing it is text if it doesn't exist. You can explicity set this property, see http://svnbook.red-bean.com/en/1.5/svn.forcvs.binary-and-trans.html

Solution 10 - Svn

It usually does this by default for you, but if it isn't you need to look into file properties and propset.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNickView Question on Stackoverflow
Solution 1 - SvnstormlashView Answer on Stackoverflow
Solution 2 - SvnEvil AndyView Answer on Stackoverflow
Solution 3 - SvnKTamasView Answer on Stackoverflow
Solution 4 - Svnuser1454388View Answer on Stackoverflow
Solution 5 - SvnJan KrügerView Answer on Stackoverflow
Solution 6 - Svngrammar31View Answer on Stackoverflow
Solution 7 - SvnBrian R. BondyView Answer on Stackoverflow
Solution 8 - SvnAdrian PetrescuView Answer on Stackoverflow
Solution 9 - SvnPaul DixonView Answer on Stackoverflow
Solution 10 - SvnFrank WilesView Answer on Stackoverflow