双点“.."有什么区别和三点“..."在 Git 差异提交范围内? [英] What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
问题描述
以下命令有什么区别?:
git diff foo master # agit diff foo..master # bgit diff foo...master # c
换句话说,git diff foo..bar
和git diff foo bar
完全一样;两者都会向您展示 foo
和 bar
两个分支的提示之间的区别.另一方面,git diff foo...bar
会告诉你merge base"和merge base"之间的区别.两个分支和 bar
的尖端.合并基础"通常是这两个分支之间共同的最后一次提交,因此此命令将向您显示您在 bar
上的工作引入的更改,同时忽略在 foo
上所做的所有更改> 同时.
关于git diff
中的..
和...
符号,您只需要了解这些.不过……
...这里的一个常见混淆来源是 ..
和 ...
在诸如 git log 之类的命令中使用时的含义略有不同
期望一组提交作为一个或多个参数.(这些命令最终都使用 gitrev-list
从参数中解析提交列表.)
..
和 ...
对 git log
的意义可以用图形表示如下:
所以,git rev-list foo..bar
向你展示了分支 bar
上的所有内容,这些内容不在分支 foo
上.另一方面,git rev-list foo...bar
显示了 foo
或 bar 中的所有提交
,但不是两者.第三张图只是表明,如果您列出两个分支,您将获得其中一个或两个分支中的提交.
好吧,无论如何,我觉得这一切都有些令人困惑,而且我认为提交图有帮助 :)
¹ 我只说通常"因为在解决合并冲突时,例如,git diff
将显示三路合并.
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 manual talks about it:
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.
but isn't totally clear to me.
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.
The command git diff
typically¹ 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:
# 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
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.
That's all you need to know about the ..
and ...
notations in git diff
. However...
... 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.)
The meaning of ..
and ...
for git log
can be shown graphically as below:
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
or bar
, 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.
Well, I find that all a bit confusing, anyway, and I think the commit graph diagrams help :)
¹ I only say "typically" since when resolving merge conflicts, for example, git diff
will show you a three-way merge.
这篇关于双点“.."有什么区别和三点“..."在 Git 差异提交范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!