我需要在我的 repo 协议(protocol)中获得一些差异,这些差异与 repo 协议(protocol)的基础无关,而是相对于给定的基础或给定的路径。
默认我得到:
git diff
diff --git a/path/to/file b/path/to/file
index 0cc125e..9bf911e 100644
--- a/path/to/file
+++ b/path/to/file
但我想要的是这样的:
git diff --prefix=/new/path/to
diff --git a/new/path/to/file b/new/path/to/file
index 0cc125e..9bf911e 100644
--- a/new/path/to/file
+++ b/new/path/to/file
我查看了 --relative 选项(不是我要找的)、--src/dst-prefix(这些只能更改“a”或“b”部分。我是否遗漏了一些基本的东西?
最佳答案
git diff
从存储库的根目录打印(已更改文件的)路径 - 无论您在执行命令时身在何处。
git diff --relative
将从您所在的目录打印路径。
因此,如果您需要的路径不是从 repo-root 开始的,请向下移动 (cd) 到您的路径所在的目录(在您的 repo 树中)。
关于git - (git) diff 输出相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23000086/