如何在Git中获取某个分支与所有其他分支之间的提交数量的差异?

时间:2016-03-02 10:08:03

标签: git

我不确定下图的正确名称是什么,但可以找到

  • 在Github上:

enter image description here

    TFS中的
  • enter image description here

所以我的问题是:

  • Git中是否有标准命令显示某个分支与所有其他分支之间的提交数量的差异?

2 个答案:

答案 0 :(得分:1)

这个问题看起来很像你的问题:Show git ahead and behind info for all branches including remotes

我不知道任何直接执行此操作的标准git命令,一个显示ab之间提交次数的命令是:

git rev-list --count a..b

我在this other answer中修改了上面的答案,并提出了一个脚本来获取两个分支的计数器:

file ./ahead.sh :
#!/bin/bash
left=$1
right=$2

leftahead=`git rev-list --count $right..$left`
rightahead=`git rev-list --count $left..$right`

echo "$left (ahead $leftahead) | (behind $rightahead) $right"

用法:

$ ./ahead.sh HEAD origin/master
HEAD (ahead 7) | (behind 0) origin/master

您可以调整它以遍历所有分支头并将HEAD与命名分支进行比较。

答案 1 :(得分:0)

结合wc命令将为您提供提交计数。

  

git log --oneline branch_a..branch_b | wc -l <​​/ p>