Git 何时将文件显示为已修改,而实际上并非如此?



git diff的输出显示我的一个文件的完整内容已被删除,然后重新添加。这是为什么呢?

diff --git a/templates/appengine/go/app.yaml b/templates/appengine/go/app.yaml
index 303af12..223b642 100644
--- a/templates/appengine/go/app.yaml
+++ b/templates/appengine/go/app.yaml
@@ -1,13 +1,13 @@
-# Right now, we direct all URL requests to the Go app we are about to
-# construct, but in the future we may add support for jQuery and Bootstrap
-# to automatically put a nice UI on the / url.
-
-application: {{ app_id.downcase }}
-version: 1
-runtime: go
-api_version: 3
-
-handlers:
-- url: /.*
-  script: _go_app
-
+# Right now, we direct all URL requests to the Go app we are about to
+# construct, but in the future we may add support for jQuery and Bootstrap
+# to automatically put a nice UI on the / url.
+
+application: {{ app_id.downcase }}
+version: 1
+runtime: go
+api_version: 3
+
+handlers:
+- url: /.*
+  script: _go_app
+

如果您已经转换了行尾(例如,通过使用在 Windows 中运行的具有 Unix 样式行尾的运行行为不佳的编辑器开始导致LF -> CR LF 转换),则预计会出现这种git diff输出。这是更改文件每一行的典型方法,除了空格更改之外,您通常无法从原始差异输出到终端破译。

git diff的选项 -w 将使git diff忽略空格更改。在你的案例中,git diff -w会是什么样子?如果它没有显示任何更改,则空格是输出的原因。

在这种情况下,您可以执行git diff | tr 'r' '~'操作,以查看git diff输出中CR字符更改为'~'个字符(假设 Unix 工具可用)。

它之所以显示它,是因为它在一次提交中被删除,然后重新添加。因此,当前状态和上次提交之间的差异已更改。

最新更新