“文件末尾没有换行"的含义是什么?日志? [英] What's the significance of the "No newline at end of file" log?
问题描述
执行 git diff
时会显示文件末尾没有换行符" .
该消息的意义是什么,它试图告诉我们什么?
What's the significance of the message and what's it trying to tell us?
推荐答案
它表示文件末尾没有换行符(通常为'\ n'
,也称为CR或CRLF)
It indicates that you do not have a newline (usually '\n'
, aka CR or CRLF) at the end of file.
简单来说,文件中的最后一个字节(或Windows中的字节)不是换行符.
That is, simply speaking, the last byte (or bytes if you're on Windows) in the file is not a newline.
之所以显示该消息,是因为否则无法分辨文件末尾有换行的地方与没有末尾的换行之间的区别.Diff无论如何都必须输出换行符,否则结果将更难于自动读取或处理.
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.
请注意,如果文件格式允许,始终将换行符放在最后一个字符是一种很好的样式.此外,例如,对于C和C ++头文件,语言标准是必需的.
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.
这篇关于“文件末尾没有换行"的含义是什么?日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!