git branch 引用中的`..` 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/850607/
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 06:27:00  来源:igfitidea点击:

What does the `..` mean in git branch reference?

git

提问by Coocoo4Cocoa

git log origin/master
git log origin/master..

What is the exact difference with the above? I'm trying to understand what exactly the ..notation does. I thought it was a range, but in this case it does something different.

与上面的具体区别是什么?我试图理解这个..符号到底是做什么的。我认为这是一个范围,但在这种情况下,它做了一些不同的事情。

回答by araqnid

With git log(and all the other Git commands that take a similar argument set), it's a specification of how to find a range of revisions, yes. Remember that in Git's general world, that means some subgraph of the revision graph--- to most people, it generally means just a range of revisions in a list. (And if you don't do much if any branching, it simplifies to that in Git too).

使用git log(以及所有其他采用类似参数集的 Git 命令),它是如何找到一系列修订的规范,是的。请记住,在 Git 的一般世界中,这意味着修订图的某个子图——对大多数人来说,这通常意味着列表中的一系列修订。(如果你不做太多分支的话,它也会简化为 Git 中的那个)。

The revision specification contains a set of positive references (starting points) and negative references (stopping points) and additional filters (limit number of revisions, grep commit text, etc.). Git starts with the positive references and goes back through the revision history, stopping when it encounters revisions that are reachable from the negative references (not necessarily just when it reaches one of the negative references themselves).

修订规范包含一组正面引用(起点)和负面引用(停止点)和附加过滤器(限制修订数量、grep 提交文本等)。Git 从正面引用开始并返回修订历史,当它遇到可从负面引用访问的修订时停止(不一定只是当它到达负面引用之一时)。

It's perhaps rather confusing that there are various shorthand notations that have evolved, that aim to make this all easier to use and yet somehow also manage to confuse- I had to spend quite a while figuring out just what "master..maint", "maint..master", etc. meant and when to use which.

可能相当令人困惑的是,已经发展出各种速记符号,旨在使这一切更容易使用,但不知何故也设法混淆 - 我不得不花很长时间弄清楚什么是“master..maint”,“ maint..master”等意思是什么时候使用哪个。

When you just say "origin/master", then that means "origin/master" is a positive reference and there are no negative references. So Git starts at origin/master and walks back through allthe revisions available-- you get the complete history of origin/master.

当你只说“origin/master”时,这意味着“origin/master”是一个正面参考,没有负面参考。因此,Git 从 origin/master 开始,然后遍历所有可用的修订版——您将获得 origin/master 的完整历史记录。

"origin/master.." is shorthand for "origin/master..HEAD" which looks kind of like it means "from origin/master up to HEAD". Which it does, effectively. It can be rewritten as "HEAD ^origin/master" or "HEAD --not origin/master". In this case, HEAD is a positive reference and "origin/master" is a negative reference. So Git starts at HEAD and walks back through the graph until it encounters a revision that is reachable from origin/master. It is likely that it will encounter origin/master itself, in fact. Note that all the references are inclusive-- the positive references themselves are output and the negative references aren't (unless you give --boundary, and then they're flagged). That means that "origin/master..HEAD" outputs nothing if HEAD and origin/master are the same revision.

“origin/master..”是“origin/master..HEAD”的简写,看起来有点像“从 origin/master 到 HEAD”。它确实有效。它可以重写为“HEAD ^origin/master”或“HEAD --not origin/master”。在这种情况下,HEAD 是一个正引用,而“origin/master”是一个负引用。因此,Git 从 HEAD 开始并返回图,直到遇到可从 origin/master 访问的修订版。事实上,它很可能会遇到 origin/master 本身。请注意,所有引用都是包含性的——正引用本身是输出,而负引用不是(除非您给出 --boundary,然后它们被标记)。这意味着“原点/主..头”

So if you have made a couple of local commits on top of the upstream version you have this kind of situation:

因此,如果您在上游版本之上进行了几次本地提交,则会出现这种情况:

steve@monolith:~/src/git <master>$ git log --pretty=oneline --abbrev-commit --decorate -n 4
ea3107d (refs/heads/master) Add another dummy comment
869c260 Add dummy comment
6345d7a (refs/remotes/origin/master, refs/remotes/origin/HEAD) Merge branch 'maint'
be427d7 allow -t abbreviation for --track in git branch

And now "git log origin/master.." means git will start at HEAD (ea3107d), which isn't reachable from origin/master, so it prints that. Then it walks back to HEAD's parent (869c260), which still isn't, so prints that. Then the next parent is 6345d7a, which isorigin/master so it stops.

现在“git log origin/master..”意味着 git 将从 HEAD (ea3107d) 开始,它无法从 origin/master 访问,所以它会打印出来。然后它走回 HEAD 的父级 (869c260),它仍然不是,所以打印出来。然后下一个父节点是 6345d7a,它原点/主节点,所以它停止了。

Note that "git log ..origin/master" does the opposite-- tries to walk back from origin/master to HEAD. In this case, it won't print anything. But if I checked out "origin/maint", it would print the revisions on origin/master that were not on origin/maint: so in general, try to think of "A..B" as "revisions in B that are not in A", and remember that omitting A or B means "HEAD".

请注意,“git log ..origin/master”的作用正好相反——尝试从 origin/master 返回到 HEAD。在这种情况下,它不会打印任何内容。但是,如果我检查“origin/maint”,它会在 origin/master 上打印不在 origin/maint 上的修订:所以一般来说,尝试将“A..B”视为“B 中不存在的修订”在 A”中,并记住省略 A 或 B 表示“HEAD”。

Just for extra super duper confusion, there is also a notation "A...B". So remember to count the number of dots! In the case of A and B being in a line of revisions, there is no real difference. But what "A...B" means is the revisions in either A or B that are not in any of the merge bases for A and B. So if A and B are on divergent branches, it shows all the commits made on either since they diverged.

只是为了额外的超级骗子混淆,还有一个符号“A...B”。所以记得数点点数!在 A 和 B 处于同一修订行的情况下,没有真正的区别。但是“A...B”的意思是 A 或 B 中的修订版本不在 A 和 B 的任何合并基础中。因此,如果 A 和 B 在不同的分支上,它会显示在任一分支上所做的所有提交因为他们分道扬镳了。

The "long form" for a revision range ("B --not A") allows you to specify things like "all revisions on local branches that are not on any remote-tracking branch" ("--branches --not --remotes"). This argument list is parsed by many Git commands ("git rev-list" being the core one), including gitk. So you can do "gitk --branches --not --remotes" to see your local changes graphically.

修订范围的“长格式”(“B --not A”)允许您指定诸如“本地分支上不在任何远程跟踪分支上的所有修订”(“--branches --not --”)之类的内容遥控器”)。这个参数列表被许多 Git 命令解析(“git rev-list”是核心命令),包括 gitk。因此,您可以执行“gitk --branches --not --remotes”以图形方式查看本地更改。

And finally for mega-bonus confusion, commands like "git diff" accept the same sort of shorthand syntax, but it doesn't mean (quite) the same thing. git diffactually takes two revisions and compares them, which is not the same as a range-- remember that a revision range in Git is a subgraph, not just a list. "git diff A..B" is equivalent to "git diff A B". "git diff A...B" means "show the changes in B since it diverged from A". Confusing? Just a bit: for example, "git log A...B" and "git log B...A" mean the same thing, but "git diff A...B" and "git diff B...A" don't.

最后,对于巨额奖金的混淆,像“git diff”这样的命令接受相同类型的速记语法,但这并不意味着(完全)相同的事情。git diff实际上需要两个修订并比较它们,这与范围不同 - 请记住,Git 中的修订范围是一个子图,而不仅仅是一个列表。“git diff A..B”相当于“git diff A B”。“git diff A...B”的意思是“显示 B 与 A 不同的变化”。令人困惑?只是一点点:例如,“git log A...B”和“git log B...A”意思相同,但是“git diff A...B”和“git diff B...A” “ 别。

回答by FelipeC

git log origin/master

Would be like (fake command):

会像(假命令):

git log INITIAL..origin/master

While:

尽管:

git log origin/master..

Is:

是:

git log origin/master..HEAD

回答by besen

I think it IS a range. The ".." command will show you the commits between the origin/master last commit and whatever is the last commit on the branch you're working on.

我认为这是一个范围。“..”命令将显示源/主最后一次提交与您正在处理的分支上的最后一次提交之间的提交。

You can also specify the branch you want to compare by putting it after the .., so it will become

您也可以通过将它放在 .. 之后来指定要比较的分支,因此它会变成

git log origin/master..<branch_name>

You can also use the commit identifiers to filter the output, for example:

您还可以使用提交标识符来过滤输出,例如:

git log 663f4c..fec6b

Try git help logto see other options :-)

尝试git help log查看其他选项:-)

回答by Ltf4an

My own mnemonic way to remember the semantics...

我自己的记忆语义的助记方法......

I think of 'git log start..end' in terms of date range where startrepresents the older part of history, and endfor the more recent history. However, unlike date range, commit range is not a linear walkback and has no relation to actual timing, but rather a set subtraction, i.e.:

我认为 'git log start..end' 就日期范围而言,其中start代表历史的较旧部分,而end代表最近的历史。但是,与日期范围不同,提交范围不是线性回溯,与实际时间无关,而是一组减法,即:

(commits reachable from "end") - (commits reachable from "start")

Remember that the start(to be excluded) in a commit range represents a set of one or more commits, not one single commit.

请记住,提交范围中的开始(要排除)代表一组一个或多个提交,而不是单个提交。

Effectively, it refers to all commits created between 'start' (exclusive) and 'end' (inclusive).

实际上,它指的是在“开始”(不包括)和“结束”(包括在内)之间创建的所有提交。