Pacerier Pacerier - 5 months ago 43
Git Question

No newline at end of file

When doing a

git diff
it says "No newline at end of file".

Ok, there is no newline at end of file. What's the big deal?

What's the significance of the message and what's it trying to tell us?


It indicates that you do not have a newline (usually '\n', aka CR or CRLF) at the end of file.

That is, simply speaking, the last byte (or bytes if you're on Windows) in the file is not a newline.

The message is displayed because otherwise there is no way to tell the difference between a file where there is a newline at the end and one where is not. Diff has to output a newline anyway, or the result would be harder to read or process automatically.

Note that it is a good style to always put the newline as a last character if it is allowed by the file format. Furthermore, for example, for C and C++ header files it is required by the language standard.