'git log origin / master'与'git log origin / master'之间的区别 [英] Difference between 'git log origin/master' vs 'git log origin/master..'

查看:298
本文介绍了'git log origin / master'与'git log origin / master'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

与上面的确切区别是什么?我试图理解 .. 符号的确切含义。我认为这是一个范围,但在这种情况下,它做了一些不同的事情。 使用 git log 解析方案 (以及所有其他采用类似参数集的Git命令),这是如何找到一系列修订版的规范,是的。请记住,在Git的一般世界中,这意味着修订图的一些子图---对于大多数人来说,它通常意味着列表中的一系列修订。 (如果你没有做太多的分支,那么它也简化为Git)。

修订规范包含一组正面引用(起点)和负面引用(停止点)和其他过滤器(限制修订版本号,grep提交文本等)。 Git从肯定引用开始,回溯到修订历史记录,当它遇到可从负面引用访问的修订时停止(不一定当它到达其中一个否定引用本身时)。



可能让人困惑的是,有各种各样的速记符号已经发展,旨在使这一切更容易使用,但也以某种方式混淆了 - 我不得不花费相当长的时间来弄清楚主人..maint,maint..master等意味着什么时候使用。



当你只说origin / master时,那意味着起源/主人是一个积极的参考,并没有负面的参考。因此,Git从origin / master开始,并通过 all 所有可用修订回溯 - 您将获得完整的origin / master历史记录。

origin / master ..是origin / master..HEAD的简写形式,看起来有点像从origin / master到HEAD。它有效地做到了。它可以被重写为HEAD ^ origin / master或HEAD - not origin / master。在这种情况下,HEAD是一个正面参考,origin / master是一个负面参考。因此,Git从HEAD开始,然后遍历图形,直到它遇到可从origin / master获得的修订。事实上,它很可能会遇到起源/主人本身。请注意,所有引用都是包含性的 - 正引用本身是输出,负引用不是(除非给出 - 边界,然后将其标记)。这意味着如果HEAD和origin / master是相同的版本,那么origin / master..HEAD不输出任何内容。

因此,如果您已经完成了几个本地提交上游版本的顶部,你有这种情况:

$ p $ steve @ monolith:〜/ src / git< master> $ git log --pretty = oneline --abbrev-commit --decorate -n 4
ea3107d(refs / heads / master)添加另一个虚拟注释
869c260添加虚拟注释
6345d7a(refs /合并分支'maint'
be427d7 allow -t - git分支中的--track的缩写
$ b $现在git log origin / master ..意味着git将从HEAD(ea3107d)开始,这是从origin / master不可访问的,所以它会打印它。然后它回到HEAD的父母(869c260),这仍然不是,所以打印出来。然后下一个父节点是6345d7a,它是 origin / master,因此停止。



请注意,git log ..origin / master相反 - 试图从起源/主人走回到HEAD。在这种情况下,它不会打印任何东西。但是,如果我检出origin / maint,它会打印原始/主版本上不属于origin / maint的版本:因此,一般情况下,尝试将A..B视为B中的修订版本在A中,并记住省略A或B意味着HEAD。

只是为了超级混乱,还有一个符号A ... B 。所以记住要计算点数!在A和B处于修订版本的情况下,没有真正的区别。但是,A ... B意味着A或B中的修改不在A和B的任何合并基础中。因此,如果A和B在不同的分支上,它将显示所有的提交因为他们分歧。



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



最后,对于巨额奖金混淆,命令如git差异接受相同类型的简写语法,但它并不意味着(完全)同样的事情。 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 不要。


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.

解决方案

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

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

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.

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

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.

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

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.

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.

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 log origin / master'与'git log origin / master'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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