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 a major bug!'
How do you list all the tags in the repository?
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 a major bug!'
How do you list all the tags in the repository?
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:
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.
Note: use Git 2.37 with git show-ref --heads/--tags.
To list tags I prefer:
git tag -n
The -n flag displays the first line of the annotation message along with the tag, or the first commit message line if the tag is not annotated.
You can also do git tag -n5 to show the first 5 lines of the annotation.
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
You can list all existing tags git tag or you could filter the list with git tag -l 'v1.1.*', where * acts as a wildcard. It will return a list of tags marked with v1.1.
You will notice that when you call git tag you do not get to see the contents of your annotations. To preview them you must add -n to your command: git tag -n2.
$ git tag -l -n2
v1.0 Release version 1.0
v1.1 Release version 1.1
The command lists all existing tags with maximum 3 lines of their tag message. By default -n only shows the first line. For more info be sure to check this tag related article as well.
Because the following two commands result in the same order and list length, here's a one shot example from bash:
paste <(git tag -l) <(git tag -l | xargs -n1 git rev-parse)
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.