Git diff 提交范围中的双点“..”和三点“...”之间有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7251477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:44:37  来源:igfitidea点击:

What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?

gitdiffgit-diff

提问by chrisjlee

What are the differences between the following commands?:

以下命令有什么区别?:

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

The diff manualtalks about it:

diff 手册谈到了它:

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.

比较分支

$ git diff topic master    <1>
$ git diff topic..master   <2>
$ git diff topic...master  <3>
  1. 主题提示和主分支之间的变化。
  2. 和上面一样。
  3. 自主题分支从主分支启动以来发生在主分支上的更改。

but isn't totally clear to me.

但对我来说并不完全清楚。

回答by Mark Longair

Since I'd already created these images, I thought it might be worth using them in another answer, although the description of the difference between ..(dot-dot) and ...(dot-dot-dot) is essentially the same as in manojlds's answer.

由于我已经创建了这些图像,我认为在另一个答案中使用它们可能是值得的,尽管..(dot-dot) 和...(dot-dot-dot)之间差异的描述与manojlds 的 answer中的描述基本相同。

The command git difftypically1 only shows you the difference between the states of the tree between exactly two points in the commit graph. The ..and ...notations in git diffhave the following meanings:

该命令git diff通常 1 仅向您显示提交图中恰好两个点之间的树状态之间的差异。中的.....符号git diff具有以下含义:

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

为 git diff 指定提交的不同方式的说明

In other words, git diff foo..baris exactly the same as git diff foo bar; both will show you the difference between the tips of the two branches fooand bar. On the other hand, git diff foo...barwill show you the difference between the "merge base" of the two branches and the tip of bar. The "merge base" is usually the last commit in common between those two branches, so this command will show you the changes that your work on barhas introduced, while ignoring everything that has been done on fooin the mean time.

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

That's all you need to know about the ..and ...notations in git diff. However...

这就是您需要了解的关于..和 中的...符号的全部内容git diff。然而...



... a common source of confusion here is that ..and ...mean subtly different things when used in a command such as git logthat expects a set of commits as one or more arguments. (These commands all end up using git rev-listto parse a list of commits from their arguments.)

...混乱的常见原因这里是.....一个命令中使用时,如意味着微妙的不同的东西git log期望一个组提交的一个或多个参数的。(这些命令最终都git rev-list用于解析来自其参数的提交列表。)

The meaning of ..and ...for git logcan be shown graphically as below:

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

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

为 git log 指定提交范围的不同方法的说明

So, git rev-list foo..barshows you everything on branch barthat isn't also on branch foo. On the other hand, git rev-list foo...barshows you all the commits that are in either fooorbar, but not both. The third diagram just shows that if you list the two branches, you get the commits that are in either one or both of them.

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

Well, I find that all a bit confusing, anyway, and I think the commit graph diagrams help :)

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

1 I only say "typically" since when resolving merge conflicts, for example, git diffwill show you a three-way merge.

1 我只说“典型地”,因为在解决合并冲突时,例如,git diff会向您展示三向合并。

回答by DolphinDream

My consolidated version of the ..vs ...with diffvs log

我的..vs ...with diffvs log 的合并版本

Diff vs Log & .. vs ..

Diff vs Log & .. vs ..

回答by manojlds

git diff foo masterDiff between the top (head) commits of foo and master.

git diff foo masterfoo 和 master 的顶部(头部)提交之间的差异。

git diff foo..masterAnother way of doing the same thing.

git diff foo..master做同样事情的另一种方式。

git diff foo...masterDiff from the common ancestor (git merge-base foo master) of foo and master to tip of master. In other words, shows only the changes that master branch has introduced since its common ancestor with foo.

git diff foo...mastergit merge-base foo masterfoo 和 master的共同祖先 ( ) 到 master 的尖端的差异。换句话说,只显示 master 分支自其与 foo 的共同祖先以来引入的更改。

This examplefrom GitHub explains when to use the two:

这个来自 GitHub 的例子解释了何时使用这两个:

For instance, if you create a ‘dev' branch and add a function to a file, then go back to your ‘master' branch and remove a line from the README, and then run something like this:

$ git diff master dev

It will tell you that a function was added from the first file and a line was added to the README. Why? Because on the branch, the README still has the original line, but on ‘master' you've removed it - so directly comparing the snapshots looks like ‘dev' added it.

What you really want to compare is what ‘dev' has changed since your branches diverged. To do that, Git has a nice little shorthand:

$ git diff master...dev

例如,如果您创建一个“dev”分支并将一个函数添加到文件中,然后返回到“master”分支并从自述文件中删除一行,然后运行如下所示:

$ git diff master dev

它会告诉您从第一个文件中添加了一个函数,并且在自述文件中添加了一行。为什么?因为在分支上,自述文件仍然有原始行,但是在“master”上你已经删除了它——所以直接比较快照看起来像“dev”添加了它。

您真正想要比较的是自从您的分支出现分歧以来“开发”发生了什么变化。为了做到这一点,Git 有一个很好的速记:

$ git diff master...dev

回答by italiano40

git diff foo master

will show the differences between the topic and master branch at that point in time

将显示该时间点的主题和主分支之间的差异

git diff foo..master

this will also show the differences between the topic and master branch in that point in time

这也将显示该时间点的主题和主分支之间的差异

git diff foo...master

this will show all the differences between when the topic was made from the branch and after

这将显示从分支创建主题时和之后的所有差异

so the first 2 commands are the same and last one just shows a wider view in the diff history

所以前 2 个命令是相同的,最后一个只是在 diff 历史中显示更广泛的视图

回答by yanhaijing

git log tree

git 日志树

The top picture is equivalent to the bottom graph tree

上图相当于下图树

A0 <- A1 <- A2 <- A3 (master)
   \
    C0 <- C1 (test)

A picture is worth a thousand words, the difference between .....^is shown below.

一张图一千字,区别.....^如下图。

$ git log master..test
# output C0 C1

$ git log ^master test
# output C0 C1

$ git log master…test
# output A1 A2 A3 C0 C1