【问题标题】:git get the branch where the last commit have been donegit 获取最后一次提交的分支
【发布时间】:2017-06-19 10:50:57
【问题描述】:

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

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 

但它看起来很奇怪。

【问题讨论】:

  • 您想如何简化它?这有什么问题?
  • 这不是便携式的:)

标签: git bash


【解决方案1】:

你可以这样做:

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 -n 1 | awk '{print $1}'这样的东西吗?
  • 我正在考虑类似“git rev-parse --abbrev-ref
猜你喜欢
  • 2012-08-31
  • 2022-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-17
相关资源
最近更新 更多