Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-svn

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?

like image 715
Pacerier Avatar asked Apr 28 '11 03:04

Pacerier


People also ask

Why is newline at end of file important?

If content is added to the end of the file, then the line that was previously the last line will have been edited to include a newline character. This means that blame ing the file to find out when that line was last edited will show the text addition, not the commit before that you actually wanted to see.

How do I fix warning no newline at end of file?

Open the file in an editor, go to the last line of the file, and hit enter to add a blank line to the end of the file. Though, besides that, you should be using #include <iostream> instead of <iostream. h> . Then put in a using std::cout; after it.

Should I have newline at end of file?

So, it turns out that, according to POSIX, every text file (including Ruby and JavaScript source files) should end with a \n , or “newline” (not “a new line”) character. This acts as the eol , or the “end of line” character.

Why does Github care about newline at end of file?

Having a newline at the end of the file allows files to be concatenated. If you miss the newline then when you concatenate files, the first line of the second file will be placed at the end of the last line of the first file, on the same line.


1 Answers

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.

like image 86
Alexander Gladysh Avatar answered Oct 18 '22 05:10

Alexander Gladysh