git - 如何列出所有的 Git 标签?

标签 git git-tag

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

git tag v1.0.0 -m 'finally a stable release'
git tag v2.0.0 -m 'oops, there was still a major bug!'

如何列出存储库中的所有标签?

最佳答案

git tag

应该够了。参见 git tag man page


你还有:

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.


最近(“How to sort git tags? ”,适用于 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.


同时列出了:

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

注:git ready article on tagging不赞成轻量级标签。

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.


也就是说, Charles Bailey 指出 ' git tag -m "..." ' 实际上意味着一个正确的(未签名的注释)标签(选项' -a '),而不是一个轻量级的标签。所以你对你的初始命令很好。


这不同于:

git show-ref --tags -d

其中列出了标签及其提交(参见“Git Tag list, display commit sha1 hashes”)。
注意 -d为了取消引用带注释的标记对象(它们有自己的提交 SHA1)并显示实际标记的提交。

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

备注:use Git 2.37git show-ref --heads/--tags .

关于git - 如何列出所有的 Git 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1064499/

相关文章:

具有多个分支的 Git pull - 与错误的分支 merge

git - 获取git标签的时间和日期

git - 远程标签未在本地显示

git - 如何将旧分支转换为 GitHub 上的标签

git - Git 准备好被推荐给我的老板了吗?

git - 查看文件夹的 git 历史记录

git - 引用 git 存储库和分支的规范方法是什么

git 存储库

git - 我如何提交一个 git 标签?

git - 使用 GIT 进行软件版本编号