文件结尾处没有换行符 [英] No newline at end of file

查看:1783
本文介绍了文件结尾处没有换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行 git diff 时,它说文件末尾没有换行符



好吧,文件末尾没有换行符。什么是大交易?



这封邮件的意义何在?它试图告诉我们什么?

解决方案

它表示在文件末尾没有换行符(通常是'\ n',又名CR或CRLF)。简单地说,文件中的最后一个字节(或者如果你在Windows上是字节的话)不是换行符。





将显示消息,因为否则无法区分文件末尾有换行符和不是。 Diff必须输出一个换行符,否则结果将很难自动读取或处理。



请注意,始终将换行符作为最后一行字符(如果文件格式允许)。此外,例如,对于C和C ++头文件,这是语言标准所要求的。


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.

这篇关于文件结尾处没有换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆