Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何从其他分支获取具有提前提交次数的分支列表_Git_Github_Version Control - Fatal编程技术网

Git 如何从其他分支获取具有提前提交次数的分支列表

Git 如何从其他分支获取具有提前提交次数的分支列表,git,github,version-control,Git,Github,Version Control,是否有一种方法可以从其他分支获取具有提前提交数量的分支列表 考虑到这一点: master feature/one feature/two feature/three 功能/*从主功能同时创建。之后,在feature/one中创建了一个新提交。在feature/two中创建了两个新提交。在feature/three中创建了三个新提交 之后,功能/2被合并回主功能 我正在寻找得到这个结果的方法:(数字意味着分支比主分支早多少次提交) feature/two 0 feature/one 1 feat

是否有一种方法可以从其他分支获取具有提前提交数量的分支列表

考虑到这一点:

master
feature/one
feature/two
feature/three
功能/*从主功能同时创建。之后,在feature/one中创建了一个新提交。在feature/two中创建了两个新提交。在feature/three中创建了三个新提交

之后,功能/2被合并回主功能

我正在寻找得到这个结果的方法:(数字意味着分支比主分支早多少次提交)

feature/two 0
feature/one 1
feature/three 3

谢谢

您可以计算日志中的提交次数:

#! /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
中的脚本应该可以工作,但是还有一种更好的方法,也就是使用脚本

首先要认识到的是,不需要签出每个分支。我们所需要的只是“在”(包含在)给定分支上的提交计数,而不是(包含在)
master
上的提交计数,并且
master..$branch
语法足以指定这些提交

使用
git log--online
管道连接到
wc-l
将起作用,但我们可以在git中使用
git rev list--count
直接完成这项工作

最后,
git branch
是一个所谓的“陶瓷”git命令,与git的“管道”命令相比:管道命令是为脚本而设计的,而陶瓷命令则不是。通常脚本与管道命令配合使用效果更好。使用管道命令获取分支列表的方法有点繁琐:

git for-each-ref --format '%(refname:short)' refs/heads
把这些放在一起,我们得到:

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

这基本上是一样的,只是使用管道命令。

你能稍微澄清一下如何运行它吗?在Windows上?在Windows上?安装cygwin(我不确定git bash是否足够)或在MSWin中运行linux,他们说现在可以了。好的,这就是.sh脚本?(很抱歉,我没有使用linux…)@查通巴布:是的,这是一个bash脚本。