git diff merge-base 与工作树(使用 ... 符号)

标签 git git-diff

(与 Git diff branch against working tree not including merges 略有不同的问题)

本质上我想要 git diff origin/develop...working-tree

从技术上讲,我想要的是 git diff $(git-merge-base origin/develop HEAD) 它将比较 merge 基础与工作树;但是我想同时保留 ... 速记。

origin/develop... 部分计算正确的 merge 基础( merge 基础与 HEAD),但它也被硬编码为假设比较是也反对 HEAD。有没有办法保留 ... 速记引用,但与工作树不同?

最佳答案

2020 年 11 月更新:是的,现在可以了。

正在运行 git diff --merge-base <commit>相当于运行 git diff $(git merge-base <commit> HEAD)这应该让您了解 merge 基础和当前工作树之间的差异。

使用 Git 2.30(2021 年第一季度),“ git diff A...B ( man )” 学习了 “ git diff --merge-base A B ( man ),这是一个更长的表示相同内容的速记。

参见 commit cce7d6e , commit 0f5a1d4 , commit df7dbab , commit 177a830 , commit 4c3fe82 (2020 年 9 月 20 日),commit 3d09c22 (2020 年 9 月 14 日),和 commit 308d7a7 , commit a8fa6a0 , commit b277b73 , commit 8023a5e (2020 年 9 月 17 日)作者:Denton Liu ( Denton-L ) .
(由 Junio C Hamano -- gitster -- merge 于 commit b6fb70c,2020 年 11 月 2 日)

builtin/diff-index: learn --merge-base

Signed-off-by: Denton Liu

There is currently no easy way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD.
Even diff's ... notation doesn't allow this because it only works between commits.

However, the ability to do this would be desirable to a user who would like to see all the changes they've made on a branch plus uncommitted changes without taking into account changes made in the upstream branch.

Teach diff-index and diff (with one commit) the --merge-base option which allows a user to use the merge base of a commit and HEAD as the "before" side.

'git diff-index' [-m] [--cached] [--merge-base] [<common diff options>] <tree-ish> [<path>...]

git diff-index现在包含在其 man page 中:

--merge-base

Instead of comparing <tree-ish> directly, use the merge base between <tree-ish> and HEAD instead.
<tree-ish> must be a commit.

git diff现在包含在其 man page 中:

If --merge-base is given, instead of using <commit>, use the merge base of <commit> and HEAD.
git diff --merge-base A is equivalent to git diff $(git merge-base A HEAD).

git diff现在包含在其 man page 中:

in the --merge-base case and in the last two forms that use .. notations, can be any <tree>.

和:

builtin/diff-tree: learn --merge-base

Signed-off-by: Denton Liu

The previous commit introduced --merge-base a way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD.

It makes sense to extend this option to support the case where two commits are given too and behave in a manner identical to git diff A...B(man).

Introduce the --merge-base flag as an alternative to triple-dot notation.

Thus, we would be able to write the above as git diff --merge-base A B(man).

git diff-tree现在包含在其 man page 中:

--merge-base

Instead of comparing the <tree-ish>s directly, use the merge base between the two <tree-ish>s as the "before" side.
There must be two <tree-ish>s given and they must both be commits.

git diff现在包含在其 man page 中:

If --merge-base is given, use the merge base of the two commits for the "before" side.
git diff --merge-base A B is equivalent to git diff $(git merge-base A B) B.


使用 Git 2.33(2021 年第 3 季度),“ git diff ( man ) --merge-base文档已更新。

参见 commit eb44863 (2021 年 7 月 10 日)作者:Denton Liu ( Denton-L ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 6ca224f,2021 年 7 月 28 日)

git-diff: fix missing --merge-base docs

Signed-off-by: Denton Liu

When git diff --merge-base(man) was introduced at around Git 2.30, the documentation included a few errors.

In the example given for git diff --cached --merge-base, the --cached flag was omitted for the --merge-base example.
Add the missing flag.

In the git diff <commit> case, we failed to mention that --merge-base is an available option.
Give the usage of --merge-base as an option there.

Finally, there are two errors in the usage of git diff.
Firstly, we do not mention --merge-base in the git diff --cached case.
Mention it so that it's consistent with the documentation.
Secondly, we put the [--merge-base] in between <commit> and [<commit>...].
Move the [--merge-base] so that it's beside [<options>] which is a more logical grouping.

git diff现在包含在其 man page 中:

git diff --cached --merge-base A is equivalent to git diff --cached $(git merge-base A HEAD).

git diff现在包含在其 man page 中:

'git diff' [<options>] [--merge-base] <commit> [--] [<path>...]

git diff现在包含在其 man page 中:

If --merge-base is given, instead of using <commit>, use the merge base of <commit> and HEAD.
git diff --merge-base A is equivalent to git diff $(git merge-base A HEAD).

关于git diff merge-base 与工作树(使用 ... 符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47141241/

相关文章:

Git - 如何在 cherry-picking 时自动解决 "deleted by us"冲突

git - 检查 AWS 中的应用程序设置

git - "git diff"什么都不做

git - 为什么我不能 checkout 另一个 git 分支?

linux - GIT:无法推送(奇怪的配置问题)

GitHub: merge 后更改提交

git - 如何在 Windows 中克隆包含 Windows 文件系统无效符号的存储库

Git:显示两次提交之间的总文件大小差异?

Git diff 命令文档

git - git-diff 出现意外结果