sh 获取当前分支的父级

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 获取当前分支的父级相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env zsh

branch=`git rev-parse --abbrev-ref HEAD`

git show-branch | ack '\*' | ack -v "$branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'

# How it works:
# 1| Display a textual history of all commits.
# 2| Ancestors of the current commit are indicated
#    by a star. Filter out everything else.
# 3| Ignore all the commits in the current branch.
# 4| The first result will be the nearest ancestor branch.
#    Ignore the other results.
# 5| Branch names are displayed [in brackets]. Ignore 
#    everything outside the brackets, and the brackets.
# 6| Sometimes the branch name will include a ~2 or ^1 to
#    indicate how many commits are between the referenced
#    commit and the branch tip. We don't care. Ignore them.

以上是关于sh 获取当前分支的父级的主要内容,如果未能解决你的问题,请参考以下文章

递归方法:对于树形结构的表,根据当前数据获取无限极的父级名称

jquery如何获得父级的父级元素?

如何找到最近的 Git 分支的父级

如何找到最近的 Git 分支的父级

js获取父级元素

如何获取当前节点的父节点名?