Git 提交范围中的双点“..”和三点“...”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/462974/
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 commit ranges?
提问by Pat Notz
Some Git commands take commit ranges and one valid syntax is to separate two commit names with two dots ..
, and another syntax uses three dots ...
.
一些 Git 命令采用提交范围,一种有效的语法是用两个点分隔两个提交名称..
,另一种语法使用三个点...
。
What are the differences between the two?
两者之间有什么区别?
采纳答案by Pieter
It depends on whether you're using a log
command or a diff
command. In the log
case, it's in the man git-rev-parse
documentation:
这取决于您使用的是log
命令还是diff
命令。在这种log
情况下,它在man git-rev-parse
文档中:
To exclude commits reachable from a commit, a prefix ^ notation is used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones reachable from r1.
This set operation appears so often that there is a shorthand for it. When you have two commits r1 and r2 (named according to the syntax explained in SPECIFYING REVISIONS above), you can ask for commits that are reachable from r2 excluding those that are reachable from r1 by "^r1 r2" and it can be written as "r1..r2".
A similar notation "r1...r2" is called symmetric difference of r1 and r2 and is defined as "r1 r2 --not $(git merge-base --all r1 r2)". It is the set of commits that are reachable from either one of r1 or r2 but not from both.
要从提交中排除可访问的提交,使用前缀 ^ 表示法。例如 ^r1 r2 表示可从 r2 访问的提交,但排除可从 r1 访问的提交。
这个集合操作经常出现,所以有一个简写。当您有两个提交 r1 和 r2(根据上面的 SPECIFYING REVISIONS 中解释的语法命名)时,您可以请求可从 r2 访问的提交,不包括通过“^r1 r2”从 r1 可访问的提交,它可以写为“r1..r2”。
类似的符号“r1...r2”称为 r1 和 r2 的对称差,定义为“r1 r2 --not $(git merge-base --all r1 r2)”。它是可从 r1 或 r2 之一但不能从两者中访问的一组提交。
Which basically means that you'll get all commits that are in either of the two branches, but not in both.
这基本上意味着您将获得两个分支中任何一个中的所有提交,但不会同时获得两个分支中的所有提交。
In the diff
case, it's in the man git-diff
documentation:
在这种diff
情况下,它在man git-diff
文档中:
git diff [--options] <commit>...<commit> [--] [<path>...] This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.
git diff [--options] <commit>...<commit> [--] [<path>...] This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.
Which is a bit fuzzy. Basically it means it shows only the differences in that branch compared to another branch: it looks for the last common commit with the first committish you gave it, and then diffs the second committish to that. It's an easy way to see what changes are made in that branch, compared to this branch, without taking notice of changes in this branch only.
这有点模糊。基本上这意味着它只显示该分支与另一个分支的差异:它使用您提供的第一个 committish 查找最后一个常见提交,然后将第二个 committish 与该分支进行比较。与此分支相比,这是一种查看该分支中进行了哪些更改的简单方法,而无需仅注意此分支中的更改。
The ..
is somewhat simpler: In the git-diff
case, it's the same as a git diff A B
and just diffs A against B. In the log
case, it shows all commits that are in B but not in A.
该..
稍微简单:在git-diff
情况下,这是相同的git diff A B
,只是一个diff文件对B.在log
情况下,它表明在B,而不是在A中的所有提交
回答by
Using Commit Ranges with Git Log
在 Git 日志中使用提交范围
When you're using commit ranges like ..
and ...
with git log
, the difference between them is that, for branches A and B,
当你使用像..
和...
with这样的提交范围时git log
,它们之间的区别在于,对于分支 A 和 B,
git log A..B
will show you all of the commits that B has that A doesn't have, while
将向您展示B 拥有而 A 没有的所有提交,而
git log A...B
will show you boththe commits that A has and that B doesn't have, and the commits that B has that A doesn't have, or in other words, it will filter out all of the commits that both A and B share, thus only showing the commits that they don'tboth share.
会告诉你这两个A有B没有的提交和,以及提交该B已经是一个不具备,或者换句话说,它会过滤掉所有提交的是A和B份额,因此只显示他们不共享的提交。
Visualization with Venn Diagrams & Commit Trees
使用维恩图和提交树进行可视化
Here is a visual representation of git log A..B
. The commits that branch B contains that don't exist in A is what is returned by the commit range, and is highlighted in red in the Venn diagram, and circled in blue in the commit tree:
这是 的可视化表示git log A..B
。分支 B 包含但在 A 中不存在的提交是提交范围返回的内容,在维恩图中以红色突出显示,在提交树中以蓝色圈出:
These are the diagrams for git log A...B
. Notice that the commits that are sharedby both branches are not returned by the command:
这些是 的图表git log A...B
。请注意,两个分支共享的提交不会由命令返回:
Making the Triple-Dot Commit Range ...
More Useful
使三点提交范围...
更有用
You can make the triple-dot commit range ...
more useful in a log command by using the --left-right
option to show which commits belong to which branch:
...
通过使用--left-right
选项显示哪些提交属于哪个分支,您可以使三点提交范围在日志命令中更有用:
$ git log --oneline --decorate --left-right --graph master...origin/master
< 1794bee (HEAD, master) Derp some more
> 6e6ce69 (origin/master, origin/HEAD) Add hello.txt
In the above output, you'll see the commits that belong to master
are prefixed with <
, while commits that belong to origin/master
are prefixed with >
.
在上面的输出中,您将看到属于的提交以master
为前缀<
,而属于的提交以origin/master
为前缀>
。
Using Commit Ranges with Git Diff
在 Git Diff 中使用提交范围
Someday I might add my own explanation for how the commit ranges work with git diff
, but for now, you might want to check out What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?.
有一天我可能会添加我自己的关于提交范围如何使用的解释git diff
,但是现在,您可能想查看Git diff commit 中的双点“..”和三点“...”之间的区别是什么范围?.