git分支引用中的`..'是什么意思? [英] What does the `..` mean in git branch reference?

查看:1959
本文介绍了git分支引用中的`..'是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

使用git log(以及所有其他采用相似参数集的Git命令),它是如何查找修订范围的规范,是的.请记住,在Git的一般世界中,这意味着修订图的某些子图-对大多数人来说,它通常仅意味着列表中的修订范围. (而且,如果您没有做太多分支的话,它也会简化为Git中的分支).

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).

修订规范包含一组正引用(起始点)和负引用(终止点)以及其他过滤器(修订数量限制,grep提交文本等). 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).

也许已经使各种速记符号演变了,这让人感到困惑,其目的是使这一切变得更易于使用,但又以某种方式也造成了混淆-我不得不花相当长的时间弄清楚"master..maint"是什么. ,"maint..master"等的含义以及何时使用.

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.

当您只说来源/母版"时,则表示来源/母版"是肯定的参考,没有否定的参考.因此,Git从起源/母版开始,然后浏览 all 的所有可用修订-您可以获得起源/母版的完整历史记录.

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 all the revisions available-- you get the complete history of origin/master.

"origin/master .."是"origin/master..HEAD"的简写,看起来有点像从起源/母版到HEAD".它能有效地做到这一点.可以将其重写为"HEAD ^ origin/master"或"HEAD --not origin/master".在这种情况下,HEAD是肯定的参考,"origin/master"是否定的参考.因此,Git从HEAD开始,然后回头浏览图形,直到遇到从原点/原版可以访问的修订版本为止.实际上,它很可能会遇到原点/原版本身.请注意,所有引用都是包容性的-正引用本身是输出,否定引用不是(除非您给出--boundary,然后将其标记).这意味着,如果HEAD和origin/master是相同的修订版,则"origin/master..HEAD"将不输出任何内容.

"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.

因此,如果您在上游版本的基础上进行了几次本地提交,则会遇到这种情况:

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

现在,"git log origin/master .."表示git将在HEAD(ea3107d)处启动,而HEAD/origin无法从origin/master到达,因此将其打印出来.然后,它返回到HEAD的父级(869c260),但仍不是,因此将其打印出来.然后,下一个父对象是6345d7a,它是 起源/主节点,因此它停止了.

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 is origin/master so it stops.

请注意,"git log ..origin/master"执行相反的操作–尝试从原点/主目录退回到HEAD.在这种情况下,它不会打印任何内容.但是,如果我签出"origin/maint",它会在原始/母版上打印不在原始/母版上的修订:因此,通常,请尝试将"A..B"视为"B中未在原版/母版上的修订".在"A"中,请记住,省略A或B就是"HEAD".

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".

仅出于超级超级骗子的困惑,还有一个符号"A ... B".因此,请记住要计算点数!在A和B处于修订版本的情况下,没有真正的区别.但是,"A ... B"的意思是A或B中的修订都不在A和B的任何合并基础中.因此,如果A和B在不同的分支上,则它将显示对A或B进行的所有提交因为他们分歧了.

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.

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

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.

最后,对于巨大的混乱,"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" 不要.

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 diff actually 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分支引用中的`..'是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆