What's the significance of the 'No newline at end of file' log?

Question

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

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

Answer

It indicates that you do not have a newline (usually \n, aka LF 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, in text files, if it is allowed by the file format. Furthermore, for example, for C and C++ header files it is required by the language standard.

How to unstage large number of files without deleting the content

How do you copy and paste into Git Bash