git - (git) diff 输出相对路径?

标签 git diff patch git-diff difference

我需要在我的 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/

相关文章:

git - 创建新分支时,基础分支是什么?

git 存储库忽略所有 .dll

algorithm - N序列的最长公共(public)子序列(不同用途)

c++ - 比较两个包含 double 的文件

SVN 差异 : Why are some files marked as binary

python - 如何使用 Python 和 matplotlib 获取动画补丁而不是 n 次绘制的补丁

ubuntu - 使用 Ansible 和 apt,如何将 bash 更新为可远程利用的安全漏洞 CVE-2014-6271?

git - 哪个提交有这个 Blob ?

linux - Buildroot - 在每次构建时重新提取 Github 包

git - git 的 master 分支应该包含什么