如何列出所有 Git 标签?
在我的存储库中,我使用以下命令创建了标签。
git tag v1.0.0 -m 'finally a stable release'
git tag v2.0.0 -m 'oops, there was still a major bug!'
如何列出存储库中的所有标签?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
应该足够了。 请参阅
git tag
手册页您还可以:
最近(“如何对 git 标签进行排序?”,适用于 Git 2.0+)
其中列出了两者:
注意:有关标记的 git Ready 文章不赞成轻量级标签。
话虽这么说,Charles Bailey 指出 '
git 标签 - m "..."
' 实际上意味着一个正确的(无符号注释)标签(选项 '-a
'),而不是一个轻量级标签。 所以你对最初的命令很满意。这不同于:
列出标签及其提交(请参阅“Git 标签列表,显示提交 sha1 哈希”)。
请注意
-d
以便取消引用带注释的标记对象(具有自己的提交 SHA1)并显示实际的标记提交。同样, git show --name-only将列出标签和关联的提交。
注意:使用 Git 2.37 和
git show-ref --heads/--tags
。Hi-Angel 添加了 评论:
should be enough. See
git tag
man pageYou also have:
More recently ("How to sort git tags?", for Git 2.0+)
That lists both:
Note: the git ready article on tagging disapproves of lightweight tag.
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:
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
.Hi-Angel adds in the comments:
要列出我喜欢的标签:
-n
标志显示注释消息的第一行以及标签,或者如果标签未注释则显示第一个提交消息行。您还可以执行 git tag -n5 来显示注释的前 5 行。
To list tags I prefer:
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.以下是查找远程标签的方法:
git ls-remote --tags origin
And here is how you find the remote tags:
git ls-remote --tags origin
另外,
git show-ref
也相当有用,因此您可以直接将标签与对应的提交关联起来:Also
git show-ref
is rather useful, so that you can directly associate tags with correspondent commits:列出 Git 中的可用标签非常简单。 只需输入
git tag
(带有可选的-l
或--list
)。您还可以搜索与特定模式匹配的标签。
获取 git 存储库上的最新标签
该命令查找可从提交访问的最新标签。 如果标签指向提交,则仅显示标签。 否则,它会在标记名称后添加标记对象顶部的附加提交数量以及最近提交的缩写对象名称。
将
--abbrev
设置为0
时,该命令可用于查找最接近的不带任何后缀的tagname
:其他示例:< /strong>
如何修剪远程上不存在的本地 git 标签
简单来说,如果您尝试执行类似
git fetch -p 的操作-t
,从 git 版本1.9.4
开始将无法工作。但是,有一个简单的解决方法在最新版本中仍然有效:
Listing the available tags in Git is straightforward. Just type
git tag
(with optional-l
or--list
).You can also search for tags that match a particular pattern.
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.
With
--abbrev
set to0
, the command can be used to find the closesttagname
without any suffix:Other examples:
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 version1.9.4
.However, there is a simple workaround that still works in latest versions:
尝试制作
git tag
,如果不尝试制作git fetch
然后git tag
,应该就足够了。Try to make
git tag
it should be enough if not try to makegit fetch
thengit tag
.要查看有关最新可用标签的详细信息,我有时会使用:
To see details about the latest available tag I sometimes use:
您可以列出所有现有标签
git tag
,也可以使用git tag -l 'v1.1.*'
过滤列表,其中*
充当通配符。 它将返回标有v1.1
的标签列表。您会注意到,当您调用 git tag 时,您看不到注释的内容。 要预览它们,您必须将
-n
添加到命令中:git tag -n2
。v1.0 发布版本 1.0
v1.1 发布版本 1.1
该命令列出所有现有标签,最多包含 3 行标签消息。 默认情况下
-n
仅显示第一行。 有关更多信息,请务必查看此标签相关文章。You can list all existing tags
git tag
or you could filter the list withgit tag -l 'v1.1.*'
, where*
acts as a wildcard. It will return a list of tags marked withv1.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
.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.如果你想在本地检查你的标签名称,你必须转到你创建标签的路径(本地路径)。
意味着你放置物品的地方。
然后输入命令:
它将显示该标签名称下的所有对象。
我在 Teradata 工作,对象意味着视图、表等
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:
It will show all the objects under that tag name.
I am working in Teradata and object means view, table etc
由于以下两个命令会产生相同的顺序和列表长度,因此这里是来自 bash 的一次性示例:
Because the following two commands result in the same order and list length, here's a one shot example from bash:
对于 GUI 来说,我刚刚发现“gitk”支持命名视图。
视图有多个用于选择提交的选项。 一个方便的就是一个盒子
选择“所有标签”。
这似乎对我来说可以看到标签。
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.