git 带注释和未注释的标签有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11514075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:08:03  来源:igfitidea点击:

What is the difference between an annotated and unannotated tag?

gittagsgit-tag

提问by user462301

If I want to tag the current commit. I know both of the following command lines work:

如果我想标记当前提交。我知道以下两个命令行都有效:

git tag <tagname>

and

git tag -a <tagname> -m '<message>'

What is the difference between these commands?

这些命令有什么区别?

回答by Todd A. Jacobs

TL;DR

TL; 博士

The difference between the commands is that one provides you with a tag message while the other doesn't. An annotated tag has a message that can be displayed with git-show(1), while a tag without annotations is just a named pointer to a commit.

这些命令之间的区别在于,一个为您提供标记消息,而另一个不提供。带注释的标签有一条消息可以用 git-show(1) 显示,而没有注释的标签只是一个指向提交的命名指针。

More About Lightweight Tags

更多关于轻量级标签

According to the documentation: "To create a lightweight tag, don't supply any of the -a, -s, or -m options, just provide a tag name". There are also some different options to write a message on annotated tags:

根据文档:“要创建轻量级标签,请不要提供任何 -a、-s 或 -m 选项,只需提供标签名称”。还有一些不同的选项可以在带注释的标签上写一条消息:

  • When you use git tag <tagname>, Git will create a tag at the current revision but will not prompt you for an annotation. It will be tagged without a message (this is a lightweight tag).
  • When you use git tag -a <tagname>, Git will prompt you for an annotation unless you have also used the -m flag to provide a message.
  • When you use git tag -a -m <msg> <tagname>, Git will tag the commit and annotate it with the provided message.
  • When you use git tag -m <msg> <tagname>, Git will behave as if you passed the -a flag for annotation and use the provided message.
  • 当您使用 时git tag <tagname>,Git 将在当前修订版上创建一个标签,但不会提示您输入注释。它将在没有消息的情况下被标记(这是一个轻量级的标记)。
  • 当您使用 时git tag -a <tagname>,Git 会提示您进行注释,除非您还使用了 -m 标志来提供消息。
  • 当您使用 时git tag -a -m <msg> <tagname>,Git 将标记提交并使用提供的消息对其进行注释。
  • 当您使用 时git tag -m <msg> <tagname>,Git 的行为就像您传递了 -a 标志进行注释并使用提供的消息一样。

Basically, it just amounts to whether you want the tag to have an annotation and some other information associated with it or not.

基本上,它仅取决于您是否希望标签具有注释以及与其相关联的其他一些信息。

回答by Luis

The bigdifference is perfectly explained here.

大的差异是完全解释在这里

Basically, lightweight tagsare just pointers to specific commits. No further information is saved; on the other hand, annotated tagsare regular objects, which have an author and a date and can be referred because they have their own SHA key.

基本上,轻量级标签只是指向特定提交的指针。不保存更多信息;另一方面,带注释的标签常规对象,它们有作者和日期,并且可以被引用,因为它们有自己的 SHA 密钥。

If knowing whotagged whatand whenis relevant for you, then use annotated tags. If you just want to tag a specific point in your development, no matter who and when did that, then lightweight tags are good enough.

如果知道标记了什么以及何时标记与您相关,请使用带注释的标记。如果你只是想在你的开发中标记一个特定的点,不管是谁在什么时候做的,那么轻量级的标签就足够了。

Normally you'd go for annotated tags, but it is really up to the Git master of the project.

通常你会选择带注释的标签,但这真的取决于项目的 Git 主人。