How can I tell if my editor is adding or removing newlines at the end of a file from the diff?
如果我有以下差异:
1 2 3 4 5 6 7 8 9 | diff --git a/file.txt b/file.txt index abcdef..ghijkl mnopqr --- a/file.txt +++ b/file.txt @@ -2,4 +2,4 @@ -This is a line of code. \ No newline at end of file +This is a line of code |
我知道我想在文件末尾添加换行符。 但是,从这个差异,我的编辑器是否在文件末尾添加或删除换行符?
我不知道
o newline at end of file
您的问题中引用的消息表明换行的新版本中添加了换行符。
如果相反,在新版本的文件中删除了换行符,你会看到:
1 2 3 4 5 6 7 8 | diff --git a/file.txt b/file.txt index abcdef..ghijkl mnopqr --- a/file.txt +++ b/file.txt @@ -2,4 +2,4 @@ -This is a line of code. +This is a line of code. \ No newline at end of file |
也就是说,
如果你想自己测试一下,这里有两个你可以运行
- noeol.txt(文件末尾没有换行符)
- eol.txt(文件末尾有换行符)
1 2 3 4 5 6 | --- noeol.txt 2016-08-13 12:55:16.000000000 +0900 +++ eol.txt 2016-08-13 12:55:23.000000000 +0900 @@ -1 +1 @@ -This is a line of code. \ No newline at end of file +This is a line of code. |
1 2 3 4 5 6 | --- eol.txt 2016-08-13 12:55:23.000000000 +0900 +++ noeol.txt 2016-08-13 12:55:16.000000000 +0900 @@ -1 +1 @@ -This is a line of code. +This is a line of code. \ No newline at end of file |