How to list all Git tags?
GitGit TagGit Problem Overview
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 Solutions
Solution 1 - Git
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
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.
Solution 2 - Git
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.
Solution 3 - Git
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
8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 refs/tags/v8.0
...
Solution 4 - Git
And here is how you find the remote tags:
git ls-remote --tags origin
Solution 5 - Git
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
Solution 6 - Git
Try to make git tag
it should be enough if not try to make git fetch
then git tag
.
Solution 7 - Git
To see details about the latest available tag I sometimes use:
git show `git describe` --pretty=fuller
Solution 8 - Git
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.
Solution 9 - Git
If you want to check you tag name locally, you have to go to the path where you have created tag(local path). Means where you have put your objects. Then type command:
git show --name-only <tagname>
It will show all the objects under that tag name. I am working in Teradata and object means view, table etc
Solution 10 - Git
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.