git的脚本:如何列出一个包含所有混帐分支机构提交 [英] git scripting: How to list all git branches containing a commit
问题描述
我可以列出<一个href=\"http://stackoverflow.com/questions/1419623/how-to-list-branches-that-contain-a-given-commit\">all含有一定犯使用分支 git的分支--list --contains
就好了。但在相关的<一个作为解释href=\"http://stackoverflow.com/questions/3846380/how-to-iterate-through-all-git-branches-using-bash-script\">question如何列出所有分支机构的,这是不应该在脚本中使用的瓷器命令。
I can list all branches containing a certain commit using git branch --list --contains
just fine. But as explained in the related question on how to list all branches, this is a porcelain command that should not be used in scripts.
后一个问题建议使用管道命令混帐的for-each-REF
,但不支持 - 包含
。
The latter question suggests to use the plumbing command git for-each-ref
, but that does not support --contains
.
什么是正确的管道接口列出包含特定提交所有分支。
What is the correct plumbing interface to list all branches that contain a certain commit.
推荐答案
使用管道命令的一个可能的解决方案混帐的for-each-REF
和 git的合并基础
(后者由约阿希姆自己的建议):
One possible solution using the plumbing commands git-for-each-ref
and git merge-base
(the latter suggested by Joachim himself):
#!/bin/sh
# git-branchesthatcontain.sh
#
# List the local branches that contain a specific revision
#
# Usage: git branchthatcontain <rev>
#
# To make a Git alias called 'branchesthatcontain' out of this script,
# put the latter on your search path, and run
#
# git config --global alias.branchesthatcontain \
# '!sh git-branchesthatcontain.sh'
if [ $# -ne 1 ]; then
printf "%s\n\n" "usage: git branchesthatcontain <rev>"
exit 1
fi
rev=$1
git for-each-ref --format='%(refname:short)' refs/heads | \
while read ref; do
if git merge-base --is-ancestor "$rev" "$ref"; then
printf "%s\n" "$ref"
fi;
done
exit $?
该脚本可在 Jubobs /混帐别名在GitHub上。
(编辑:感谢核心转储以显示我的如何摆脱那个讨厌评估
。)
( thanks to coredump for showing me how to get rid of that nasty eval
.)
这篇关于git的脚本:如何列出一个包含所有混帐分支机构提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!