How to get the latest tag name in current branch in Git?

前端 未结 24 2174
你的背包
你的背包 2020-11-22 17:04

What\'s the simplest way to get the most recent tag in Git?

git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag

output:



        
相关标签:
24条回答
  • 2020-11-22 17:20

    I'm not sure why there are no answers to what the question is asking for. i.e. All tags (non-annotated included) and without the suffix:

    git describe --tags --abbrev=0
    
    0 讨论(0)
  • 2020-11-22 17:21
    git tag --sort=committerdate | tail -1
    
    0 讨论(0)
  • 2020-11-22 17:23
    git tag -l ac* | tail -n1
    

    Get the last tag with prefix "ac". For example, tag named with ac1.0.0, or ac1.0.5. Other tags named 1.0.0, 1.1.0 will be ignored.

    git tag -l [0-9].* | tail -n1
    

    Get the last tag, whose first char is 0-9. So, those tags with first char a-z will be ignored.

    More info

    git tag --help # Help for `git tag`
    

    git tag -l <pattern>
    

    List tags with names that match the given pattern (or all if no pattern is given). Running "git tag" without arguments also lists all tags. The pattern is a shell wildcard (i.e., matched using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown.


    tail -n <number> # display the last part of a file
    tail -n1 # Display the last item 
    

    Update

    With git tag --help, about the sort argument. It will use lexicorgraphic order by default, if tag.sort property doesn't exist.

    Sort order defaults to the value configured for the tag.sort variable if it exists, or lexicographic order otherwise. See git-config(1).

    After google, someone said git 2.8.0 support following syntax.

    git tag --sort=committerdate
    
    0 讨论(0)
  • 2020-11-22 17:23

    git describe --abbrev=0 --tags

    If you don't see latest tag, make sure of fetching origin before running that:

    git remote update

    0 讨论(0)
  • 2020-11-22 17:25

    You can execute: git describe --tags $(git rev-list --tags --max-count=1) talked here: How to get latest tag name?

    0 讨论(0)
  • 2020-11-22 17:25

    git describe --tags

    returns the last tag able to be seen by current branch

    0 讨论(0)
提交回复
热议问题