How to list all Git tags?

前端 未结 10 2377
囚心锁ツ
囚心锁ツ 2020-11-28 17:40

In my repository, I have created tags using the following commands.

git tag v1.0.0 -m \'finally a stable release\'
git tag v2.0.0 -m \'oops, there was still         


        
10条回答
  •  春和景丽
    2020-11-28 17:54

    Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list).

    $ git tag
    v5.5
    v6.5
    

    You can also search for tags that match a particular pattern.

    $ git tag -l "v1.8.5*"
    v1.8.5
    v1.8.5-rc0
    v1.8.5-rc1
    v1.8.5-rc2
    

    Getting latest tag on git repository

    The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

    git describe
    

    With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:

    git describe --abbrev=0
    

    Other examples:

    git describe --abbrev=0 --tags # gets tag from current branch
    git describe --tags `git rev-list --tags --max-count=1` // gets tags across all branches, not just the current branch
    

    How to prune local git tags that don't exist on remote

    To put it simple, if you are trying to do something like git fetch -p -t, it will not work starting with git version 1.9.4.

    However, there is a simple workaround that still works in latest versions:

    git tag -l | xargs git tag -d  // remove all local tags
    git fetch -t                   // fetch remote tags
    

提交回复
热议问题