When running git diff
, you may meet it says “No newline at end of file”. Obviously the message tells there is a newline at the end for a file and there isn’t for the other. But is it a big deal? What’s the point of newline at end of file? w
Yes, it matters. It’s not only about good or bad styles to or not to add a newline to end of a file. It may lead to unexpected result if there is not a newline in the end of a file. For example when you run wc -l test.txt
to get the count of lines, it would output a number with one line fewer for there is not a newline in the end. Furthermore, newline in the end is required for some language compilers. Therefore, always add a newline in end of file.