gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:09:36 27 4
gpt4 key购买 nike

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

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/

27 4 0