Get git current branch/tag name

后端 未结 3 1150
梦如初夏
梦如初夏 2020-12-15 05:10

How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but t

3条回答
  •  無奈伤痛
    2020-12-15 05:53

    This command can print name in this priority: tag > branch > commit

    git describe --tags --exact-match 2> /dev/null \
      || git symbolic-ref -q --short HEAD \
      || git rev-parse --short HEAD
    

提交回复
热议问题