简体   繁体   English

如何列出所有 Git 标签?

[英]How to list all Git tags?

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?您如何列出存储库中的所有标签?

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), refname ”(字典顺序),
  • " version:refname " or " v:refname " (tag names are treated as versions). version:refname ”或“ v:refname ”(标签名称被视为版本)。

Prepend " - " to reverse sort order.在前面加上“ - ”以反转排序顺序。


That lists both:这列出了两者:

  • annotated tags : full objects stored in the Git database.注释的标签:存储在 Git 数据库中的完整对象。 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).并且可以使用 GNU Privacy Guard (GPG) 进行签名和验证。
  • lightweight tags : simple pointer to an existing commit 轻量级标签:指向现有提交的简单指针

Note: the git ready article on tagging disapproves of lightweight tag.注意:关于标记的 git ready 文章不赞成轻量级标记。

Without arguments, git tag creates a “lightweight” tag that is basically a branch that never moves.没有参数, git tag 会创建一个“轻量级”标签,它基本上是一个永远不会移动的分支。
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.通常,您至少希望通过 -a 选项来创建未签名的标签,或者通过 -s 或 -u 选项使用您的 GPG 密钥对标签进行签名。


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.话虽如此, Charles Bailey指出,' git tag -m "..." ' 实际上暗示了一个正确的(无符号注释)标签(选项' -a '),而不是一个轻量级的标签。 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 ").其中列出了带有提交的标签(请参阅“ 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.注意-d以取消引用带注释的标记对象(它们有自己的提交 SHA1)并显示实际的标记提交。

Similarly, git show --name-only <aTag> would list the tag and associated commit.同样, git show --name-only <aTag>将列出标签和相关的提交。

Note: use Git 2.37 with git show-ref --heads/--tags .注意:将 Git 2.37git show-ref --heads/--tags一起使用。

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 行。

Also git show-ref is rather useful, so that you can directly associate tags with 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
...

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

git ls-remote --tags origin

Listing the available tags in Git is straightforward.在 Git 中列出可用的标签很简单。 Just type git tag (with optional -l or --list ).只需输入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 版本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

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

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

git show `git describe` --pretty=fuller

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.您可以列出所有现有标签git tag或者您可以使用git tag -l 'v1.1.*'过滤列表,其中*充当通配符。 It will return a list of tags marked with v1.1 .它将返回标有v1.1的标签列表。

You will notice that when you call git tag you do not get to see the contents of your annotations.您会注意到,当您调用git tag时,您看不到注释的内容。 To preview them you must add -n to your command: git tag -n2 .要预览它们,您必须将-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.该命令列出所有现有标签,标签消息最多为 3 行。 By default -n only shows the first line.默认情况下-n只显示第一行。 For more info be sure to check this tag related article as well.有关更多信息,请务必查看此标签相关文章

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 工作,对象意味着视图、表格等

因为以下两个命令导致相同的顺序和列表长度,所以这里有一个来自 bash 的示例:

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

For a GUI to do this I have just found that 'gitk' supports named views.对于执行此操作的 GUI,我刚刚发现“gitk”支持命名视图。 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.这似乎对我看到标签有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM