git - Git diff 提交范围中的双点 ".."和三点 "..."有什么区别?

标签 git diff git-diff

以下命令之间有什么区别?:

git diff foo master   # a 
git diff foo..master  # b
git diff foo...master # c

The diff manual谈论它:

Comparing branches

$ git diff topic master    <1>
$ git diff topic..master   <2>
$ git diff topic...master  <3>
  1. Changes between the tips of the topic and the master branches.
  2. Same as above.
  3. Changes that occurred on the master branch since when the topic branch was started off it.

但我不是很清楚。

最佳答案

由于我已经创建了这些图像,所以我认为可能值得在另一个答案中使用它们,尽管 .. (点-点)和 ... (dot-dot-dot) 本质上与 manojlds's answer 中的相同.

git diff 命令通常¹ 只会向您显示提交图中正好两点之间的树状态之间的差异。 ..... 符号在 git diff 中具有以下含义:

# Left side in the illustration below:
git diff foo..bar
git diff foo bar  # same thing as above

# Right side in the illustration below:
git diff foo...bar
git diff $(git merge-base foo bar) bar  # same thing as above

An illustration of the different ways of specifying commits for git diff

换句话说,git diff foo..bargit diff foo bar 完全相同;两者都会向您显示两个分支 foobar 的提示之间的区别。另一方面,git diff foo...bar 将向您显示两个分支的“merge 基础”和 bar 的提示之间的区别。 “merge 基础”通常是这两个分支之间的最后一个共同提交,因此此命令将向您显示您在 bar 上所做的工作引入的更改,同时忽略在 上所做的一切>foo 同时。

这就是您需要了解的有关 git diff 中的 ..... 符号的全部信息。然而……


...这里一个常见的混淆来源是 ..... 在诸如 git log 之类的命令中使用时意味着微妙的不同 期望一组提交作为一个或多个参数。 (这些命令最终都使用 git rev-list 从它们的参数中解析提交列表。)

..... 对于git log 的含义可以用图形表示如下:

An illustration of the different ways of specifying ranges of commits for git log

因此,git rev-list foo..bar 向您显示分支 bar 上不在分支 foo 上的所有内容。另一方面,git rev-list foo...bar 向您显示 foo bar 中的所有提交,但不是两者。第三张图仅显示如果您列出两个分支,您将获得其中一个或两个分支中的提交。

好吧,无论如何,我发现这一切都有点令人困惑,而且我认为提交图表会有所帮助:)

¹ 我只说“通常”,因为在解决 merge 冲突时,例如,git diff 将向您显示三向 merge 。

关于git - Git diff 提交范围中的双点 ".."和三点 "..."有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7251477/

相关文章:

git - 获取不带前缀的git分支名称

git - 无法使用 Git 存储更改

git - hudson+git fatal error : Could not apply tag

css - 面向非行的差异

intellij-idea - 如何使用外部 diff 工具来比较 Intellij IDEA 中的*文件夹*?

linux - 查找不在列表中的文件

git - 标记远程 git 存储库而不克隆它

git - 在暂存区显示文件的 git diff

git - 如何为 *.tex 文件自动使用 git diff --word-diff 选项而不是其他文件?

git diff - 显示行尾更改?