如何列出所有 Git 标签?

发布于 2024-07-26 00:15:01 字数 216 浏览 5 评论 0原文

在我的存储库中,我使用以下命令创建了标签。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

烂人 2024-08-02 00:15:01
git tag

应该足够了。 请参阅 git tag 手册页


您还可以:

git tag -l <pattern>

列出名称与给定模式匹配的标签(如果没有给出模式,则列出所有标签)。
不带参数输入“git tag”也会列出所有标签。


最近(“如何对 git 标签进行排序?”,适用于 Git 2.0+)

git tag --sort=<type>

按特定顺序排序。

支持的类型是:

  • refname”(字典顺序),
  • version:refname”或“v:refname”(标记名称被视为版本)。

在前面添加“-”以反转排序顺序。


其中列出了两者:

  • 带注释的标签:Git 数据库中存储的完整对象。 它们经过校验和; 包含标记者姓名、电子邮件和日期; 有标签消息; 并且可以使用 GNU Privacy Guard (GPG) 进行签名和验证。
  • 轻量级标签:简单指向现有提交的指针

注意:有关标记的 git Ready 文章不赞成轻量级标签。

如果没有参数,git tag 创建一个“轻量级”标签,基本上是一个永远不会移动的分支。
不过,轻量级标签仍然有用,也许可以用于标记已知的好(或坏)版本,或者将来可能需要使用的一堆提交。
尽管如此,您可能不想推送这些类型的标签

通常,您至少需要传递 -a 选项来创建未签名的标签,或者通过 -s 或 -u 选项使用 GPG 密钥对标签进行签名。


话虽这么说,Charles Bailey 指出 'git 标签 - m "..."' 实际上意味着一个正确的(无符号注释)标签(选项 '-a'),而不是一个轻量级标签。 所以你对最初的命令很满意。


这不同于:

git show-ref --tags -d

列出标签及其提交(请参阅“Git 标签列表,显示提交 sha1 哈希”)。
请注意 -d 以便取消引用带注释的标记对象(具有自己的提交 SHA1)并显示实际的标记提交。

同样, git show --name-only将列出标签和关联的提交。

注意:使用 Git 2.37git show-ref --heads/--tags


Hi-Angel 添加了 评论

“列出以标签α开头的标签”:

git tag --sort=-creatordate --contains α 
  
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.

Note: use Git 2.37 with git show-ref --heads/--tags.


Hi-Angel adds in the comments:

"listing tags starting with tag α":

git tag --sort=-creatordate --contains α
提笔落墨 2024-08-02 00:15:01

要列出我喜欢的标签:

git tag -n

-n 标志显示注释消息的第一行以及标签,或者如果标签未注释则显示第一个提交消息行。

您还可以执行 git tag -n5 来显示注释的前 5 行。

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.

清旖 2024-08-02 00:15:01

以下是查找远程标签的方法:

git ls-remote --tags origin

And here is how you find the remote tags:

git ls-remote --tags origin

╰沐子 2024-08-02 00:15:01

另外,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
...

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
...
哑剧 2024-08-02 00:15:01

列出 Git 中的可用标签非常简单。 只需输入 git tag (带有可选的 -l--list)。

$ git tag
v5.5
v6.5

您还可以搜索与特定模式匹配的标签。

$ git tag -l "v1.8.5*"
v1.8.5
v1.8.5-rc0
v1.8.5-rc1
v1.8.5-rc2

获取 git 存储库上的最新标签

该命令查找可从提交访问的最新标签。 如果标签指向提交,则仅显示标签。 否则,它会在标记名称后添加标记对象顶部的附加提交数量以及最近提交的缩写对象名称。

git describe

--abbrev 设置为 0 时,该命令可用于查找最接近的不带任何后缀的 tagname

git describe --abbrev=0

其他示例:< /strong>

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

如何修剪远程上不存在的本地 git 标签

简单来说,如果您尝试执行类似 git fetch -p 的操作-t,从 git 版本 1.9.4 开始将无法工作。

但是,有一个简单的解决方法在最新版本中仍然有效:

git tag -l | xargs git tag -d  # remove all local tags
git fetch -t                   # fetch remote tags

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
别低头,皇冠会掉 2024-08-02 00:15:01

尝试制作git tag,如果不尝试制作git fetch然后git tag,应该就足够了。

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

留一抹残留的笑 2024-08-02 00:15:01

要查看有关最新可用标签的详细信息,我有时会使用:

git show `git describe` --pretty=fuller

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

git show `git describe` --pretty=fuller
过去的过去 2024-08-02 00:15:01

您可以列出所有现有标签 git tag,也可以使用 git tag -l 'v1.1.*' 过滤列表,其中 *充当通配符。 它将返回标有 v1.1 的标签列表。

您会注意到,当您调用 git tag 时,您看不到注释的内容。 要预览它们,您必须将 -n 添加到命令中:git tag -n2

$ git tag -l -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 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.

诺曦 2024-08-02 00:15:01

如果你想在本地检查你的标签名称,你必须转到你创建标签的路径(本地路径)。
意味着你放置物品的地方。
然后输入命令:

git show --name-only <tagname>

它将显示该标签名称下的所有对象。
我在 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:

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

呆° 2024-08-02 00:15:01

由于以下两个命令会产生相同的顺序和列表长度,因此这里是来自 bash 的一次性示例:

paste <(git tag -l) <(git tag -l | xargs -n1 git rev-parse)

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)
枯寂 2024-08-02 00:15:01

对于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文