git 为什么我应该关心轻量级标签和带注释的标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4971746/
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
Why should I care about lightweight vs. annotated tags?
提问by Ben Blank
I switched from Subversion to Git as my day-to-day VCS last year and am still trying to grasp the finer points of "Git-think".
去年,我从 Subversion 切换到 Git 作为我的日常 VCS,并且仍在努力掌握“Git-think”的精髓。
The one which has been bothering me lately is "lightweight" vs. annotated vs. signed tags. It seems pretty universally accepted that annotated tags are superior to lightweight tags for all real uses, but the explanations I've found for why that's the case always seem to boil down to either "because best practices"or "because they're different". Unfortunately, those are very unsatisfying arguments without knowing whyit's best practices or how those differences are relevantto my Git usage.
最近一直困扰我的是“轻量级”与带注释与签名标签。似乎普遍接受的是,在所有实际用途中,带注释的标签都优于轻量级标签,但我找到的解释为什么总是这样似乎总是归结为“因为最佳实践”或“因为它们不同”. 不幸的是,这些都是非常不令人满意的论点,我不知道为什么这是最佳实践,也不知道这些差异与我的 Git 使用有何相关。
When I first switched to Git, lightweight tags seemed to be the best thing since sliced bread; I could just point at a commit and say "that was 1.0". I'm having trouble grasping how a tag could ever need to be more than that, but I certainly can't believe that the Git experts of the world prefer annotated tags arbitrarily! So what's all the hubbub about?
当我第一次切换到 Git 时,轻量级标签似乎是自切片面包以来最好的东西;我可以指向一个提交并说“那是 1.0”。我无法理解标签如何需要更多,但我当然无法相信世界上的 Git 专家会随意选择带注释的标签!那么喧嚣到底是怎么回事呢?
(Bonus points: Why would I ever need to sign a tag?)
(奖励积分:为什么我需要在标签上签名?)
EDIT
编辑
I've been successfully convincedthat annotated tags are a Good Thing — knowing who tagged and when is important! As a follow-up, any advice on good tag annotations? Both git tag -am "tagging 1.0" 1.0
and trying to summarize the commit log since the previous tag feel like losing strategies.
我已经成功地确信带注释的标签是一件好事——知道谁标记以及何时标记很重要!作为后续行动,对良好的标签注释有什么建议吗?双方git tag -am "tagging 1.0" 1.0
并试图总结提交日志自上次标记感觉就像失去战略。
采纳答案by Cascabel
The big plus of an annotated tag is that you know who created it. Just like with commits, sometimes it's nice to know who did it. If you're a developer and you see that v1.7.4 has been tagged (declared ready) and you're not so sure, who do you talk to? The person whose name is in the annotated tag! (If you live in a distrustful world, this also keeps people from getting away with tagging things they shouldn't.) If you're a consumer, that name is a stamp of authority: that's Junio Hamano saying this version of git is hereby released.
带注释的标签的一大优点是您知道它是谁创建的。就像提交一样,有时很高兴知道是谁做的。如果您是一名开发人员,并且您看到 v1.7.4 已被标记(宣布准备就绪)并且您不太确定,您会与谁交谈?名字在注释标签中的人!(如果你生活在一个不信任的世界里,这也可以防止人们对不应该的东西进行标记。)如果你是消费者,这个名字就是权威的印记:这是 Junio Hamano 说这个版本的 git 特此释放。
The other metadata can be helpful too - sometimes it's nice to know when that version was released, not just when the final commit was made. And sometimes the message can even be useful. Maybe it helps explain the purpose of that particular tag. Maybe the tag for a release candidate contains a bit of a status/to-do list.
其他元数据也很有用 - 有时很高兴知道该版本的发布时间,而不仅仅是最终提交的时间。有时,该消息甚至可能很有用。也许它有助于解释该特定标签的用途。也许发布候选的标签包含一些状态/待办事项列表。
Signing tags is pretty much like signing anything else - it provides one more level of security for the paranoid. Most of us aren't ever going to use it, but if you really want to verify everything before you put that software on your computer, you might want it.
签署标签与签署其他任何东西非常相似——它为偏执狂提供了更高级别的安全性。我们大多数人都不会使用它,但是如果您真的想在将该软件安装到计算机之前验证所有内容,您可能需要它。
Edit:
编辑:
As for what to write in a tag annotation, you're right - there's not always much useful to say. For a version number tag, it's implicitly understood that it marks that version, and if you're happy with your changelogs elsewhere, there's no need to put one there. In this case, it's really the tagger and date that are the most important. The only other thing I can think of is some sort of stamp of approval from a test suite. Have a look at git.git's tags: they all just say something like "Git 1.7.3 rc1"; all we really care about is Junio Hamano's name on them.
至于在标签注释中写什么,你是对的 - 说的并不总是很有用。对于版本号标签,它隐含地理解为它标记了该版本,如果您对其他地方的变更日志感到满意,则无需在那里放置一个。在这种情况下,真正重要的是标记器和日期。我唯一能想到的另一件事是测试套件的某种批准印章。看看 git.git 的标签:它们都只是说“Git 1.7.3 rc1”之类的东西;我们真正关心的是它们上的 Junio Hamano 的名字。
However, for less obviously named tags, the message could become much more important. I could envision tagging a specific special-purpose version for a single user/client, some important non-version milestone, or (as mentioned above) a release candidate with extra information. The message is then much more useful.
但是,对于不太明显的命名标签,消息可能会变得更加重要。我可以设想为单个用户/客户端、一些重要的非版本里程碑或(如上所述)带有额外信息的候选发布版本标记特定的专用版本。那么这个消息就更有用了。
回答by Koraktor
My personal, slightly different view on that topic:
我个人对这个话题的看法略有不同:
- Annotated tags are those tags meant to be published for other developers, most probably new versions (which should also be signed). Not only to see who tagged and when it was tagged, but also why (usually a changelog).
- Lightweight are more appropriate for private use, that means tagging special commits to be able to find them again. May it be to review them, check them out to test something or whatever.
- 带注释的标签是那些打算为其他开发人员发布的标签,很可能是新版本(也应该签名)。不仅要查看标记的对象和标记时间,还要查看原因(通常是更改日志)。
- 轻量级更适合私人使用,这意味着标记特殊提交以便能够再次找到它们。可能是它们,检查它们以测试某些东西或其他什么。
回答by Phil Miller
By default, Git only looks at annotated tags as a baseline for commands like git describe
. Think of annotated tags as signposts that have enduring meaning to yourself and others, while lightweight tags are more like bookmarks for your later self to find. Hence, annotated tags are worth using as a reference, while lightweight tags shouldn't be.
默认情况下,Git 只将带注释的标签视为诸如git describe
. 将带注释的标签视为对自己和他人具有持久意义的路标,而轻量级标签更像是书签,供以后自己查找。因此,带注释的标签值得作为参考,而轻量级标签不应该。
Signing a tag is an assurance of the signer's identity. It lets users verify, for example, that the Linux kernel code they've picked up is the same code that Linus Torvalds actually released. The signature can also be an assertion that the signer is vouching for the software's quality and integrity at that commit.
对标签进行签名是对签名者身份的保证。例如,它可以让用户验证他们选择的 Linux 内核代码是否与 Linus Torvalds 实际发布的代码相同。签名也可以是签名者在该提交时保证软件质量和完整性的断言。
回答by cwilper
Signing a tag is an easy way to assert the authenticity of a release.
签署标签是断言发布真实性的一种简单方法。
This is particularly useful in a DVCS because anyone can clone the repository and modify history (e.g. via git-filter-branch). If a tag is signed, the signature will not survive a git-filter-branch operation, so if you have a policy that every release is tagged and signed by a committer, it's possible to detect a bogus release tag in the repository.
这在 DVCS 中特别有用,因为任何人都可以克隆存储库并修改历史记录(例如,通过 git-filter-branch)。如果标记已签名,则签名将无法在 git-filter-branch 操作中保留,因此如果您有一个策略,即每个版本都由提交者标记和签名,则有可能在存储库中检测到伪造的发布标记。
If it weren't for signing, I wouldn't see much point in annotated tags either.
如果不是为了签名,我也不会在带注释的标签中看到太多意义。
回答by evilkos
I've found the one good use for lightweight tags - creating a release at GitHub in retrospective.
我发现了轻量级标签的一个很好的用途——回顾性地在 GitHub 上创建一个版本。
We did release our software and we had the necessary commits, we just didn't bother to maintain the 'Release' section on the GitHub. And when we gave that a little attention, we've realised that we would want to add some previous releases too, with correct old release dates for them.
我们确实发布了我们的软件并且我们进行了必要的提交,我们只是没有费心维护 GitHub 上的“发布”部分。当我们稍加注意时,我们意识到我们也希望添加一些以前的版本,并为它们提供正确的旧发布日期。
If we would just create an annotated tag on an old commit, GitHub would take the date for the release from the tag object. In contrast, when we've created a lightweight tag for this old commit, the release started showing the correct (old) date. Source @ GitHub help, 'About releases'
如果我们只是在旧提交上创建一个带注释的标签,GitHub 将从标签对象中获取发布日期。相比之下,当我们为这个旧提交创建一个轻量级标签时,发布开始显示正确的(旧)日期。 来源@GitHub 帮助,“关于发布”
It seems it's also possible to specify your desired date for an annotated commit, but it doesn't look that simple to me: https://www.kernel.org/pub/software/scm/git/docs/git-tag.html#_on_backdating_tags
似乎也可以为带注释的提交指定所需的日期,但对我来说看起来并不那么简单:https: //www.kernel.org/pub/software/scm/git/docs/git-tag。 html#_on_backdating_tags
回答by David
In my office we'll put the release webpage address in the tag body. The release webpage details all the different new features and fixes since the last release. Management won't be looking in the git repo to find out what changes happened, and it's nice to have a concise list of what's in that release.
在我的办公室,我们会将发布网页地址放在标签正文中。发布网页详细介绍了自上次发布以来所有不同的新功能和修复。管理人员不会在 git 存储库中查找发生的更改,并且拥有该版本中内容的简明列表是很好的。
回答by Nesha Zoric
Annotated tags store extra metadata such as author name, release notes, tag-message, and date as full objects in the Git database. All this data is important for a public release of your project.
带注释的标签将额外的元数据(例如作者姓名、发行说明、标签消息和日期)存储为 Git 数据库中的完整对象。所有这些数据对于项目的公开发布都很重要。
git tag -a v1.0.0
git tag -a v1.0.0
Lightweight tags are the simplest way to add a tag to your git repository because they store only the hash of the commit they refer to. They can act like "bookmarks" to a commit, as such, they are great for private use.
轻量级标签是将标签添加到 git 存储库的最简单方法,因为它们仅存储它们引用的提交的哈希值。它们可以充当提交的“书签”,因此,它们非常适合私人使用。
git tag v1.0.0
git 标签 v1.0.0
You can sort, list, delete, show and edit old tags. All these functions will help you to identify specific release versions of your code. I found this articlethat could help you to get a better idea what tags can do.
您可以排序、列出、删除、显示和编辑旧标签。所有这些函数都将帮助您识别代码的特定发布版本。我发现这篇文章可以帮助您更好地了解标签可以做什么。
回答by Ezh
For me important difference is lightweight tag doesn't have timestamp. Let's say you added several lightweight tags:
对我来说重要的区别是轻量级标签没有时间戳。假设您添加了几个轻量级标签:
git tag v1
git tag v2
git tag v3
and then, maybe later, you want to get last added lightweight tag. There is no way to do it. Neither "git describe" nor "git tag" will not give you chronologically last lightweight tag. "git tag -l" can return all of them or sort them in lex order, but not by date/time. "git describe --tags" will return "v1" which is definitely not last added tag.
然后,也许稍后,您希望获得最后添加的轻量级标签。没有办法做到这一点。“git describe”和“git tag”都不会给你按时间顺序最后一个轻量级标签。“git tag -l”可以返回所有这些或按 lex 顺序对它们进行排序,但不能按日期/时间。“git describe --tags”将返回“v1”,这绝对不是最后添加的标签。
From the other hand, if you add annotated tags:
另一方面,如果添加带注释的标签:
git tag v1 -m v1
git tag v2 -m v1
git tag v3 -m v1
you always can get timestamp of every tag and "git describe" will sure return "v3" which is really last added tag.
您总是可以获得每个标签的时间戳,并且“git describe”肯定会返回“v3”,这实际上是最后添加的标签。