How to list all Git tags?

前端 未结 10 2343
囚心锁ツ
囚心锁ツ 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:48

    Also git show-ref is rather useful, so that you can directly associate tags with correspondent commits:

    $ git tag
    osgeolive-6.5
    v8.0
    ...
    
    $ git show-ref --tags
    e7e66977c1f34be5627a268adb4b9b3d59700e40 refs/tags/osgeolive-6.5
    8f27e65bffffd7d4b8515ce620fb485fdd78fcdf89 refs/tags/v8.0
    ...
    
    0 讨论(0)
  • 2020-11-28 17:51

    To see details about the latest available tag I sometimes use:

    git show `git describe` --pretty=fuller
    
    0 讨论(0)
  • 2020-11-28 17:53

    Try to make git tag it should be enough if not try to make git fetch then git tag.

    0 讨论(0)
  • 2020-11-28 17:54
    git tag
    

    should be enough. See git tag man page


    You also have:

    git tag -l <pattern>
    

    List tags with names that match the given pattern (or all if no pattern is given).
    Typing "git tag" without arguments, also lists all tags.


    More recently ("How to sort git tags?", for Git 2.0+)

    git tag --sort=<type>
    

    Sort in a specific order.

    Supported type is:

    • "refname" (lexicographic order),
    • "version:refname" or "v:refname" (tag names are treated as versions).

    Prepend "-" to reverse sort order.


    That lists both:

    • annotated tags: full objects stored in the Git database. They’re checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).
    • lightweight tags: simple pointer to an existing commit

    Note: the git ready article on tagging disapproves of lightweight tag.

    Without arguments, git tag creates a “lightweight” tag that is basically a branch that never moves.
    Lightweight tags are still useful though, perhaps for marking a known good (or bad) version, or a bunch of commits you may need to use in the future.
    Nevertheless, you probably don’t want to push these kinds of tags.

    Normally, you want to at least pass the -a option to create an unsigned tag, or sign the tag with your GPG key via the -s or -u options.


    That being said, Charles Bailey points out that a 'git tag -m "..."' actually implies a proper (unsigned annotated) tag (option '-a'), and not a lightweight one. So you are good with your initial command.


    This differs from:

    git show-ref --tags -d
    

    Which lists tags with their commits (see "Git Tag list, display commit sha1 hashes").
    Note the -d in order to dereference the annotated tag object (which have their own commit SHA1) and display the actual tagged commit.

    Similarly, git show --name-only <aTag> would list the tag and associated commit.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-11-28 17:56

    For a GUI to do this I have just found that 'gitk' supports named views. The views have several options for selecting commits. One handy one is a box for selecting "All tags". That seems to work for me to see the tags.

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