File detected as binary, not displayed as text in Bitbucket

Purpose

Bitbucket will display the contents of all plain text files when git detects them as not binary.  If you have a file that should display in Bitbucket and it does not, this can sometimes happen when git looks in the first few bytes of the file for null characters or non ascii characters.  When this happens Bitbucket Server will not display the file and will offer a download link instead.  You can confirm if this is the case by using vi or hexdump.  Here is an example:

Text File:

$ hexdump text.xml
0000000 3c 70 72 6f 70 65 72 74 69 65 73 3e 3c 2f 70 72
0000010 6f 70 65 72 74 69 65 73 3e 0a
000001a

This file will be detected as binary:

$ hexdump bin.xml
0000000 00 3c 70 72 6f 70 65 72 74 69 65 73 3e 3c 2f 70
0000010 72 6f 70 65 72 74 69 65 73 3e 0a
000001b

cat will not show this blank byte at the start of the file:

$ cat bin.xml
<properties></properties>

vi will show it like this:

^@<properties></properties>


Solution

  • Delete the characters in the file with vi that causes git to report it as binary.
  • Push the updated file to Bitbucket Server in a new commit.
  • Confirm the file can be viewed as text not binary in Bitbucket.

 

Last modified on Apr 18, 2017

Was this helpful?

Yes
No
Provide feedback about this article

Not finding the help you need?

Ask the community

Powered by Confluence and Scroll Viewport.