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
What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
提问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>
- Changes between the tips of the topic and the master branches.
- Same as above.
- 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>
- 主题提示和主分支之间的变化。
- 和上面一样。
- 自主题分支从主分支启动以来发生在主分支上的更改。
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 diff
typically1 only shows you the difference between the states of the tree between exactly two points in the commit graph. The ..
and ...
notations in git diff
have the following meanings:
该命令git diff
通常 1 仅向您显示提交图中恰好两个点之间的树状态之间的差异。中的..
和...
符号git diff
具有以下含义:
In other words, git diff foo..bar
is exactly the same as git diff foo bar
; both will show you the difference between the tips of the two branches foo
and bar
. On the other hand, git diff foo...bar
will 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 bar
has introduced, while ignoring everything that has been done on foo
in the mean time.
换句话说,git diff foo..bar
与git diff foo bar
;完全相同。两者都会向您展示两个分支的提示之间的区别foo
和bar
。另一方面,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 log
that expects a set of commits as one or more arguments. (These commands all end up using git rev-list
to parse a list of commits from their arguments.)
...混乱的常见原因这里是..
和...
一个命令中使用时,如意味着微妙的不同的东西git log
期望一个组提交的一个或多个参数的。(这些命令最终都git rev-list
用于解析来自其参数的提交列表。)
The meaning of ..
and ...
for git log
can be shown graphically as below:
..
和...
for的含义git log
可以用图形表示如下:
So, git rev-list foo..bar
shows you everything on branch bar
that isn't also on branch foo
. On the other hand, git rev-list foo...bar
shows you all the commits that are in either foo
orbar
, 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
向您显示在foo
or 中的所有提交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 diff
will show you a three-way merge.
1 我只说“典型地”,因为在解决合并冲突时,例如,git diff
会向您展示三向合并。
回答by DolphinDream
回答by manojlds
git diff foo master
Diff between the top (head) commits of foo and master.
git diff foo master
foo 和 master 的顶部(头部)提交之间的差异。
git diff foo..master
Another way of doing the same thing.
git diff foo..master
做同样事情的另一种方式。
git diff foo...master
Diff 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...master
从git merge-base foo master
foo 和 master的共同祖先 ( ) 到 master 的尖端的差异。换句话说,只显示 master 分支自其与 foo 的共同祖先以来引入的更改。
This examplefrom GitHub explains when to use the two:
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
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