两次提交之间的git diff显示我删除并添加了相同的内容

时间:2017-11-04 17:31:29

标签: git

* d556e92 // added 789 in new line inside file1.txt (HEAD -> master)
* 79fe73c // added 456 in new line inside file1.txt
* 574a673 // added 123 to file1.txt
* c50371c // created file1.txt with no content

file1.txt in master`分支:

123
456
789

当我运行git diff 574a673..79fe73c时,我希望只看到 +456。但输出结果不同:

$ git diff 574a673..79fe73c
diff --git a/file1.txt b/file1.txt
index d800886..156626c 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1,2 @@
-123
\ No newline at end of file
+123
+456
\ No newline at end of file

我的问题:

git告诉我,我删除了“123”并在同一次提交中添加了“123”:79fe73c

1 个答案:

答案 0 :(得分:2)

您已删除

123

并将其替换为

123\n

新行在行终止符号后开始,因此添加新行实际上会修改之前的行,因为\n附加了它。