git分支在本地分支的前面和后面? [英] git branch ahead and behind for local branch?

查看:86
本文介绍了git分支在本地分支的前面和后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git branch将在前面和后面显示

  master    03ea915f82 [behind 16] test

我认为这意味着masterremote/origin/master的16位之后?

I think it means master is behind 16 of remote/origin/master ?

是否可以在本地分支机构之间前后显示?

Is it possible to show ahead and behind between local branches?

例如,我有masterdevelop,我经常更新master然后在develop中的rebase master,如果它显示类似以下内容,将会有所帮助:

For example, I have master and develop, I often update master then rebase master in develop, it would be help if it shows something like this:

  master    03ea915f82 test
  develop   1231231231 [behind master 16] test

推荐答案

git branch将在前面和后面显示

master    03ea915f82 [behind 16] test

我认为这意味着masterremote/origin/master的16位之后?

I think it means master is behind 16 of remote/origin/master ?

仅凭这一点是不可能的.计数是为分支机构主服务器设置为 upstream 的任何内容.对于-vv,上游名称包括在内:

It's not possible to tell from this alone. The count(s) is/are for whatever is set as the upstream for branch master. With -vv, the name of the upstream is included:

$ git branch -vv
* master          e0688e9b2 [origin/master: behind 479] git svn: fix
  stash-exp       8dbdf339c [origin/master: ahead 1, behind 1142] st

请注意,这里的两个分支都以origin/master作为上游,但stash-expmaster落后(stash-exp也是 1).

Note that both branches here have origin/master as their upstream, but stash-exp is more behind than master is (and stash-exp is also ahead 1).

是否可以在本地分支机构之间前后显示?

Is it possible to show ahead and behind between local branches?

是的-但每个分支只能在上游获得一个.如果将本地分支A的上游设置为本地分支B,则只会看到A相对于B向前还是向后多远,而不是origin/A.

Yes—but you get only one upstream per branch. If you set the upstream of local branch A to local branch B, you see only how far ahead or behind A is with respect to B, and not to origin/A.

您可以计算自己的计数. git branchgit status都在这里运行(内部等效)git rev-list --count:

You can compute your own counts. What both git branch and git status do here is to run (the internal equivalent of) git rev-list --count:

$ git rev-list --count stash-exp..origin/master
1142
$ git rev-list --count origin/master..stash-exp
1

这是打印的两个计数git branch -vv.我们可以一次获得两个:

These are the two counts git branch -vv printed. We can get both at once:

$ git rev-list --count --left-right stash-exp...origin/master
1       1142

请注意此处的三个点,它们会产生对称差异:可以从任一分支尖端到达提交,但不能从两个分支尖端到达. git rev-list中的--count代码在使用--left-right时分别对两者进行计数,并在左侧打印左侧计数(1),在右侧打印右侧计数(1142).左右互换,计数互换:

Note the three dots here, which produce a symmetric difference: commits reachable from either branch tip, but not from both branch tips. The --count code in git rev-list counts the two separately when using --left-right, and prints the left hand side count (1) on the left and the right hand side count (1142) on the right. Swap left and right sides and the counts swap:

$ git rev-list --count --left-right origin/master...stash-exp
1142    1

如果我想找到两个本地分支(例如masterstash-exp)之间的关系,可以在这里使用它们:

If I wish to find the relationship between two local branches, such as master and stash-exp, I can use those here:

$ git rev-list --count --left-right master...stash-exp
663     1

这告诉我从master的顶端可以到达的663个提交,从stash-exp的顶端无法到达的提交,还有从stash-exp的顶端无法到达的1个提交,从stash-exp的顶端无法到达的提交c1>.

which tells me there are 663 commits reachable from the tip of master that are not reachable from the tip of stash-exp, and 1 commit reachable from the tip of stash-exp that is not reachable from the tip of master.

这篇关于git分支在本地分支的前面和后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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