已经有一些有用的答案,但没有给出所要求的:一个列表或分支(对我来说,这意味着分支名称,而不是提交 ID)。
获取提示分支名称列表
{
echo "** Below is list of tip branches a.k.a. final nodes."
echo "** These aren't reachable from any other branches."
echo "** Removing them is potentially DANGEROUS: it would make some commit unreachable."
TIPS=$( git rev-list --branches --children | grep -v ' ' | sort )
{ while read branchname commitid message
do grep $commitid < <(echo $TIPS) -q && echo $branchname
done
} < <(git branch -v --no-abbrev | sed 's/\*//' )
echo "** end of list"
}
结果如下所示:
** Below is list of tip branches a.k.a. final nodes.
** These aren't reachable from any other branches.
** Removing them is potentially DANGEROUS: it would make some commit unreachable.
feature-workingonit
dev
** end of list
获取非提示分支名称列表
在整理东西时,您可能希望看到非尖端的分支。这是一种获取它们列表的方法。唯一的变化是&& 变成了||。
{
echo "** Below is list of non-tip branches a.k.a. inner nodes."
echo "** These are reachable from other branches."
echo "** If you remove them, all commits would stay reachable, but be careful anyway."
TIPS=$( git rev-list --branches --children | grep -v ' ' | sort )
{ while read branchname commitid message
do grep $commitid < <(echo $TIPS) -q || echo $branchname
done
} < <(git branch -v --no-abbrev | sed 's/\*//' )
echo "** end of list"
}
结果如下所示:
** Below is list of non-tip branches a.k.a. inner nodes.
** These are reachable from other branches.
** If you remove them, all commits would stay reachable, but be careful anyway.
feature-alreadymerged
master
** end of list
获取带有提交 ID 和消息的非提示分支名称列表
您可以随意装饰,例如通过更改:
echo $branchname
进入
echo -e "$branchname\t$commitid\t$message"
结果如下所示:
** Below is list of non-tip branches a.k.a. inner nodes.
** These are reachable from other branches.
** If you remove them, all commits would stay reachable, but be careful anyway.
feature-alreadymerged 426ac5186841876163970afdcc5774d46641abc4 Cool feature foo, ref task #1234
master 39148238924687239872eea425c0e837fafdcfd9 Some commit
** end of list
然后,您可以在自己喜欢的工具中查看这些分支,看看是否可以删除它们。