我需要在我的回购中获得一些与回购基础无关的差异,而是相对于给定的基数或给定路径。
默认情况下,我得到:
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”部分。我错过了一些基本的东西吗?
答案 0 :(得分:9)
似乎--src-prefix
和--dst-prefix
是您要求的:
$ cd .../git/builtin
$ ed - var.c << end
> 0a
> xxx
> .
> wq
> end
$ git diff
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53..5210013 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -1,3 +1,4 @@
+xxx
/*
* GIT - The information manager from hell
*
(到目前为止,非常标准;现在:)
$ git diff --src-prefix=a/new/ --dst-prefix=b/new/
diff --git a/new/builtin/var.c b/new/builtin/var.c
index aedbb53..5210013 100644
--- a/new/builtin/var.c
+++ b/new/builtin/var.c
@@ -1,3 +1,4 @@
+xxx
/*
* GIT - The information manager from hell
*
您可以将其与--relative
:
$ git diff --relative --src-prefix=a/new/ --dst-prefix=b/new/
diff --git a/new/var.c b/new/var.c
index aedbb53..5210013 100644
--- a/new/var.c
+++ b/new/var.c
@@ -1,3 +1,4 @@
+xxx
/*
* GIT - The information manager from hell
*
$
答案 1 :(得分:4)
git diff
打印来自回购根目录的路径(已更改的文件) - 无论您在执行命令时的位置。
git diff --relative
将打印您所在目录的路径。
因此,如果您需要不从repo-root开始的路径向下移动(cd)到您的路径开始的目录(在您的repo树中)。