Get git current branch/tag name

后端 未结 3 1151
梦如初夏
梦如初夏 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:37

    I think you want this:

    git symbolic-ref -q --short HEAD || git describe --tags --exact-match
    

    That will output the value of HEAD, if it's not detached, or emit the tag name, if it's an exact match. It'll show you an error otherwise.

提交回复
热议问题