2016-08-13 10 views
1

私は、次のdiffをお持ちの場合:diffからファイルの最後にエディタが改行を追加したり削除したりするかどうかを確認する方法はありますか?

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 

を私はI want the newline at the end of the fileことを理解しています。しかし、この差分から、エディタはファイルの最後に改行を追加したり削除したりしていますか?

\No newline at end of fileは、テキストエディタが削除したもの(上記)または追加されたもの(下記)を参照することはできません。

答えて

1

あなたの質問に引用されたメッセージは、改行されたファイルの新しいバージョンに改行が追加されたことを示しています。改行は、ファイルの新しいバージョンでは削除されていた代わりに、場合

は差分を取っされている、あなたはこれを参照してくださいね。

ある
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 

は、\ No newline at end of file部分は差分の非常に最後の行になります。


あなたはこの自分をテストしたい場合は、ここにあなたが上diff -uを実行できる2つのファイルがある:あり

  • noeol.txt(ファイルの末尾に改行を持っていない)
  • eol.txtは(

    :ファイルの末尾に改行)

diff -u noeol.txt eol.txtはあなたにこれを与えます

--- 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. 

diff -u eol.txt noeol.txtはあなたにこれを与える:

--- 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 
関連する問題