有没有办法从其他分支获取具有提交数量的分支列表?
考虑这个分支:
master
feature/one
feature/two
feature/three
feature / *从master同时创建的地方。比,在feature / one中创建了一个新提交。在feature / two中创建了两个新提交。在feature / three中创建了三个新提交。
然后,功能/两个被合并回主人。
我正在寻找得到这个结果的方法:(数字意味着在主人面前提交了多少次提交。
feature/two 0
feature/one 1
feature/three 3
由于
答案 0 :(得分:2)
choroba's answer中的脚本应该可以运行但是有一些更好的方法,也可以使用脚本。
首先要意识到的是,没有必要检查每个分支。我们想要的只是给定分支“on”(包含在其中)的提交计数,这些提交也不在master
上,包含在master..$branch
中,git log --online
语法就足以指定那些。< / p>
使用wc -l
管道传输到git rev-list --count
会有效,但我们可以使用git branch
直接在Git中执行此操作。
最后,git for-each-ref --format '%(refname:short)' refs/heads
是一个所谓的“瓷器”Git命令,与Git的“管道”命令相对应:管道命令设计用于编写脚本,而瓷器命令则不是。通常脚本可以更好地使用管道命令。使用管道命令获取分支列表的方法略显冗长:
git for-each-ref --format '%(refname:short)' refs/head |
while read branch; do
printf "%s " $branch # %s just in case $branch contains a %
git rev-list --count master..$branch
done
将这些放在一起我们得到:
currentColor
这基本上是一回事,只是使用管道命令。
答案 1 :(得分:1)
您可以计算日志中的提交次数:
#! /bin/bash
git branch \
| while read b ; do
b=${b#\* } # Remove the current branch mark.
git checkout "$b" &>/dev/null
printf "$b "
git log --oneline master..@ | wc -l
done