Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: a NUL byte in commit log message not allowed

Tags:

git

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?

like image 558
James Avatar asked Oct 31 '13 11:10

James


5 Answers

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.

like image 141
Mark Avatar answered Oct 06 '22 21:10

Mark


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"

like image 42
Pedro Rodrigues Avatar answered Oct 06 '22 21:10

Pedro Rodrigues


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

like image 21
Mudaser Ali Avatar answered Oct 06 '22 23:10

Mudaser Ali


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
like image 38
dirtybird Avatar answered Oct 06 '22 21:10

dirtybird


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

like image 27
Yann VR Avatar answered Oct 06 '22 23:10

Yann VR