Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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_Bash - Fatal编程技术网

git获取上次提交的分支

git获取上次提交的分支,git,bash,Git,Bash,我正在寻找获得分支的方法,在那里完成了最后一次提交,现在我正在做类似的事情 last_co_branch=$(git branch --sort=-committerdate| head -1| grep -o -e "develop" -e "master") if [[ "$last_co_branch" == "master" ]]; then # stuff ... fi if [[ "$last_co_branch" == "develop" ]]; then #

我正在寻找获得分支的方法,在那里完成了最后一次提交,现在我正在做类似的事情

last_co_branch=$(git branch --sort=-committerdate| head -1| grep -o -e "develop" -e "master")

if [[ "$last_co_branch" == "master" ]]; then

  # stuff ... 
fi 

if [[ "$last_co_branch" == "develop" ]]; then

  # stuff ... 
fi 

但是看起来很奇怪

您可以这样做:

last_co_branch=$(git for-each-ref --count=1 --sort=-committerdate refs/heads/ --format='%(refname:short)')
if [[ "$last_co_branch" == "master" ]]; then
  # stuff ... 
fi 
if [[ "$last_co_branch" == "develop" ]]; then
  # stuff ... 
fi 

您想如何简化它?这有什么问题吗?这是不可移植的:)谢谢,我想,它会更短:)你的意思是像
git branch-v | head-n1 | awk'{print$1}'
?我在考虑类似“git rev parse--abbrev ref”的东西吗