如何列出所有 Git 标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1064499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to list all Git tags?
提问by Léo Léopold Hertz ??
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?
你如何列出存储库中的所有标签?
回答by VonC
git tag
should be enough. See git tag
man page
应该够了。参见git tag
手册页
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.
列出名称与给定模式匹配的标签(如果没有给出模式,则列出所有标签)。
键入不带参数的“git tag”,也会列出所有标签。
More recently ("How to sort git tags?", for Git 2.0+)
最近(“如何对 git 标签进行排序?”,对于 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.
按特定顺序排序。
支持的类型是:
- "
refname
" (字典序),- "
version:refname
" 或 "v:refname
"(标记名称被视为版本)。前置“-”以反转排序顺序。
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
- 带注释的标签:存储在 Git 数据库中的完整对象。它们是校验和的;包含标记者姓名、电子邮件和日期;有标签信息;并且可以使用 GNU Privacy Guard (GPG) 进行签名和验证。
- 轻量级标签:指向现有提交的简单指针
Note: the git ready article on taggingdisapproves 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.
没有参数, git tag 创建一个“轻量级”标签,它基本上是一个永远不会移动的分支。
轻量级标签仍然有用,也许用于标记已知的好(或坏)版本,或者您将来可能需要使用的一堆提交。
不过,您可能不想推送这些类型的标签。通常,您至少希望通过 -a 选项来创建未签名的标签,或者通过 -s 或 -u 选项使用 GPG 密钥对标签进行签名。
That being said, Charles Baileypoints 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.
话虽如此,Charles Bailey指出 ' git tag -m "..."
' 实际上意味着一个正确的(无符号注释)标签(选项 ' -a
'),而不是一个轻量级的标签。所以你很擅长你的初始命令。
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.
其中列出了带有提交的标签(请参阅“ Git 标签列表,显示提交 sha1 哈希”)。
注意-d
为了取消引用带注释的标记对象(它们有自己的提交 SHA1)并显示实际的标记提交。
Similarly, git show --name-only <aTag>
would list the tag and associated commit.
同样,git show --name-only <aTag>
将列出标签和相关的提交。
回答by finn
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.
该-n
标志显示注释消息的第一行以及标签,如果未注释标签,则显示第一行提交消息。
You can also do git tag -n5
to show the first 5 lines of the annotation.
您还git tag -n5
可以显示注释的前 5 行。
回答by Campa
Also git show-ref
is rather useful, so that you can directly associate tagswith correspondent commits:
也git show-ref
相当有用,因此您可以直接将标签与相应的提交相关联:
$ git tag
osgeolive-6.5
v8.0
...
$ git show-ref --tags
e7e66977c1f34be5627a268adb4b9b3d59700e40 refs/tags/osgeolive-6.5
8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 refs/tags/v8.0
...
回答by Dimitri Dewaele
And here is how you find the remote tags:
以下是您如何找到远程标签:
git ls-remote --tags origin
git ls-remote --tags origin
回答by toto
Try to make git tag
it should be enough if not try to make git fetch
then git tag
.
尝试制作git tag
它应该足够了,如果不尝试制作git fetch
那么git tag
。
回答by Lyes CHIOUKH
Listing the available tags in Git is straightforward. Just type git tag
(with optional -l
or --list
).
在 Git 中列出可用标签很简单。只需键入git tag
(带有可选的-l
或--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
在 git 存储库上获取最新标签
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:
随着--abbrev
设置0
,该命令可以用来找出最接近tagname
无任何后缀:
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
如何修剪远程上不存在的本地 git 标签
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
.
简而言之,如果您尝试执行类似 的操作git fetch -p -t
,则从 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
回答by Andrei Sura
To see details about the latest available tag I sometimes use:
要查看有关最新可用标签的详细信息,我有时会使用:
git show `git describe` --pretty=fuller
回答by Tanaya
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
它将显示该标签名称下的所有对象。我在 Teradata 工作,对象意味着视图、表格等
回答by Nesha Zoric
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
.
您可以列出所有现有标签git tag
,也可以使用 过滤列表git tag -l 'v1.1.*'
,其中*
用作通配符。它将返回标有 的标签列表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
看不到注释的内容。要预览它们,您必须添加-n
到您的命令中:git tag -n2
.
$ git tag -l -n2
v1.0 Release version 1.0
v1.0 发布版本 1.0
v1.1 Release version 1.1
v1.1 发布版本 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 articleas well.
该命令列出所有现有标签,最多 3 行标签消息。默认情况下-n
只显示第一行。有关更多信息,请务必查看此标签相关文章。
回答by O. B. J.
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.
对于执行此操作的 GUI,我刚刚发现 'gitk' 支持命名视图。视图有几个选项来选择提交。一个方便的是用于选择“所有标签”的框。这似乎对我有用,可以看到标签。