How can I prevent null bytes from appearing in my GIT repository and committing messages?


I have a relatively clean install of Mac OS X Mavericks 10.9 running git version; my files are on a mounted SMB share, and I am no longer able to work properly with my GIT repositories because NULL bytes (\0's) keep appearing in all of my version-controlled files... and even in files generated on the fly by GIT.

Typing git commit -m "Test message" by hand, gives me:

error: a NULL byte in commit log message not allowed.
fatal: failed to write commit object

And if I attempt to git commit instead, the default commit message that appears in the pico view looks like this:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch feature/centos_support
# Your branch is up-to-date with 'origin/feature/centos_support'.
# Changes to be committed:
#       modified:

For a while, manually removing those NULL bytes at the end worked, and I was able to commit, but at intervals even this no longer works (the error is the same as above), and I am forced to trash my entire repo, re-clone it, and redo whatever I was trying to commit.

The fresh repository works as normal for a while, but eventually the NULL characters creep back in, and I have the same problem again.

The same NULL bytes (as above) are appearing at the start and end of files I modify, causing GIT to treat them as binary files until I manually use vi to delete the NULL rows.

  • Has anybody else experienced this, and/or found a solution?
  • What could be causing it?

I would appreciate any help you can offer.

It looks like this is a problem with OS X 10.9 Mavericks and (some?) SMB shares. There is currently no fix or workaround.

Some people have suggested connecting to the share with cifs:// instead of smb:// however this does NOT appear to solve the issue.

The issue can be reproduced as follows:

<on an SMB share>

$ echo "blah blah blah blah" > test.txt
$ more test.txt

<file is fine>

$ echo "blah" > test.txt
$ more test.txt

<file has ^@ characters at the end>

So, using the terminal, if you overwrite a file with a smaller one, then you get these NUL characters at the end. There may be other ways to cause the file to be appended or prepended with those NUL characters too.

A number of people are complaining about this, for example:

Here is the conclusion from that page:

I can replicate the null characters in Komodo Edit and Aptana Studio, so this doesn't appear to be a Netbeans specific issue, and is probably related to the NAS/SMB issue.

I forced the smb1 connection but it made no difference. Even if I eject the shares, and reconnect with cifs:// and create, modify and save a file, it's still corrupted.

It looks like Apple is going to have to resolve this, unless someone can come up with a viable workaround.

Hopefully Apple will fix this issue shortly. Until then, you could potentially use Double Commander or some other program that implements its own SMB stack.