6

I'm trying to commit some files in my Git repository, and I'm receiving this error.

This all started when I ran git rm -rf folder and git rm -rf file and tried to commit the changes. I've since been able to commit and push without these files being deleted from my remote repository, however I'm now completely stuck.

The full error is:

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

What can I do to fix this? My Google-fu has let me down on this one.

Edit:

I've just checked out these deleted files, and attempted to commit again, but it's still giving me the same error. Has my Git repo been corrupted or something?

James
  • 5,137
  • 5
  • 40
  • 80

6 Answers6

4

Seems that for some reason a NULL byte is getting it's way into your commit message, and Git doesn't like that. Try to commit from the command-line and see if that works: git commit -m "My brilliant commit message"

Pedro Rodrigues
  • 1,732
  • 11
  • 17
  • I copied and pasted your message, it worked fine. I hand write a message, it cries about it. What's weird is that I typed it straight out, no errors, no arrow keys pressed. – James Oct 31 '13 at 12:24
  • So now I've deleted the folder and file again, tried to commit, but it's not working. I'm so confused. – James Oct 31 '13 at 12:25
  • @James What do you mean by "it's not working"? What commands did you use, and what errors did you get? – Pedro Rodrigues Oct 31 '13 at 12:47
  • Same error as before. I used the same command as I copied from you, just changed my commit message. – James Oct 31 '13 at 13:07
  • @James I suspect that your Terminal is inserting NUL bytes when you type. Why it would be doing that I don't know (maybe some weird configuration?). I'd do the following test: `echo "Foo Bar" > test.txt` and then open test.txt and see if it has NUL bytes. In the meantime maybe you can workaround the problem by using some Git GUI instead of the Terminal. – Pedro Rodrigues Oct 31 '13 at 13:26
  • So what I've done now is deleted my local repo and cloned the remote again. It seems to be working through the Terminal, although I've only ran three commands, it could probably break again. *I also Quit and re-opened Terminal.* – James Oct 31 '13 at 13:34
  • Glad to know it's working. Let's hope it doesn't break again. – Pedro Rodrigues Oct 31 '13 at 14:04
4

I've had the same thing happen, for no apparent reason. Tried several things, such as a clean clone, switching from iTerm2 to Terminal... didn't make any difference. I then ended up just going with plain git commit, after which I manually typed my commit message in the following screen... and that DID solve it. Still not sure what's causing this though, but at least it's solved, sorta.

Mark
  • 56
  • 2
  • This is actually a better solution since it does in fact solve the problem every time, so I'm therefore marking this answer as the solution. – James Nov 13 '13 at 11:26
  • The above worked for me as well as restarting my computer. Problem still comes up frequently though. – Kyle Parisi Dec 10 '13 at 15:16
  • http://stackoverflow.com/a/20874631/289194 explains the cause of this issue. Are you using smb on OSX? – John Jacquay Mar 10 '14 at 15:07
1

I got this error when i copy some text from a document and paste that text for commit message; so it is due to any invalid character in my commit message; so when i just type manually my code committed easily.

MORAL OF THE STORY: So if you got this error please check your commit message; if there is any return in the of comment message please remove it

Mudaser Ali
  • 3,989
  • 3
  • 25
  • 27
1

I resolved this issue on my end based on Edward Thomson's comment on the question regarding the encoding of the log message. I had a PowerShell script that was invoking Out-File to dump information to a file (happened to be snarfing data from svn logs) that would form the git commit log. Setting the Encoding flag for Out-File to ASCII resolved this issue.

Invoke-Expression "svn log -r $rev $repoPath" | Out-File -Encoding ASCII commit.txt
git commit -F commit.txt
dirtybird
  • 422
  • 5
  • 8
1

It happens when you copy and paste the log in an editor and a line return conversion happens (\n => \r\n which creates the null bytes for every line return)

Most text editor will handle ignore byte when rendering the text so you will not see it.

Some code editor, like plnkr are smarter so paste the log message on plnkr editor. You will then see the null bytes as error characters. Fix it then use the fixed log for your commit

Yann VR
  • 486
  • 5
  • 9
0

I had the same experience with git-cola, and finally figured it out. The problem in my case is caused by an obsolete leading space in the commit message. When I removed it, everything just worked fine.