git 为什么我应该使用标签与发布/测试版分支进行版本控制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9810050/
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 13:16:23  来源:igfitidea点击:

Why should I use tags vs. release/beta branches for versioning?

gitbranchgit-tag

提问by wufoo

I've been using git for about a year and would like to use tagging to, well, tag commits at different versions. I've found lots of info on the commands to use to work with tags, but what I'd like to know is why use tagging at all if I can just create a new branch called 1.1.0and not have to cloud my mind with a whole new set of git commands?

我已经使用 git 大约一年了,我想使用标记来标记不同版本的提交。我发现了很多关于用于处理标签的命令的信息,但我想知道的是,如果我可以创建一个名为的新分支1.1.0,而不必用一个整体来模糊我的思绪,为什么还要使用标签一组新的 git 命令?

There has to be a lot of good reasons for tagging rather than branching but I'd like to know what those advantages are.

标记而不是分支必须有很多充分的理由,但我想知道这些优点是什么。

采纳答案by Hakan Deryal

Tags are mainly used for future reference to the specific version of the project, by tagging a commit. You can always use branches of course, but if you change versions a lot, you will end up with lots of unused or rarely used branches.

通过标记提交,标签主要用于将来参考项目的特定版本。当然,你总是可以使用分支,但是如果你经常更改版本,你最终会得到很多未使用或很少使用的分支。

Practically, tags are branches without branches anyway, just adding a way to reference a specific version of the project to reduce complexity.

实际上,标签无论如何都是没有分支的分支,只是添加了一种引用项目特定版本的方法以降低复杂性。

Edit: Hereis a nice way to use git that I use for all my projects.

编辑:是一种使用 git 的好方法,我用于所有项目。

回答by AD7six

A tag is immutable.

标签是不可变的

Whereas you can create a branch named "1.0.0" - you, or anyone with commit rights, can also then simply push to that branch (deliberately or not) and change what 1.0.0 means.

而您可以创建一个名为“1.0.0”的分支——您或任何拥有提交权限的人,也可以简单地推送到该分支(有意或无意)并更改 1.0.0 的含义。

You can't do that with a tag, once you create a tag - that's it; Tag 1.0.0 means exactly that and can't be changed*.

一旦你创建了一个标签,你就不能用标签来做到这一点——就是这样;标签 1.0.0 就是这个意思,不能更改*

That's the main practical difference between a tag and a branch

这是标签和分支之间的主要实际区别

*You can delete and recreate a tag thereby changing a tag, but certainly not by accident.

*您可以删除和重新创建标签从而更改标签,但绝非偶然。

回答by Justin ??????

I tend to use a workflow that incorporates both tags andbranches. Tags are good for marking released code or notable development builds. Branches are good for keeping track of all changes relevant to a specific version.

我倾向于使用包含标签分支的工作流。标签适用于标记已发布的代码或值得注意的开发版本。分支有助于跟踪与特定版本相关的所有更改。

Here's a good writeup on this type of workflow: http://nvie.com/posts/a-successful-git-branching-model/

这是关于此类工作流程的一篇很好的文章:http: //nvie.com/posts/a-successful-git-branching-model/

回答by Branko Dimitrijevic

Branch and tag are the same thing (pointer to a commit, aka. "ref"), except branch automatically moves to the next commit while tag stays forever1on the same commit.

分支和标签是一样的东西(指向提交的指针,又名“ref”),除了分支自动移动到下一个提交,而标签在同一个提交上永远保持为1

When making a release, you generally want to mark the "snapshot" of the code from which that release was built, and you want it to stay marked that way even as you continue to evolve the code, so you'd use a tag.

在发布版本时,您通常希望标记构建该版本的代码的“快照”,并且即使您继续改进代码,您也希望它保持这种标记,因此您会使用标签。

If you tried using a branch for that, it could inadvertently move to a different commit, from which the release was notbuilt.

如果您尝试为此使用分支,它可能会无意中移动到不同的提交,而发布不是从该提交构建的。



1Unless you delete the tag, of course.

1除非你删除标签,当然。

NOTE: I realize this is an old question, but I felt that the similarity (and one crucial difference) between branches and tags has not been flashed out in other answers as clearly as it could have been.

注意:我意识到这是一个古老的问题,但我觉得分支和标签之间的相似性(以及一个重要的区别)在其他答案中并没有像它本来的那样清楚地闪现出来。

回答by ralphtheninja

You use tags to note important commits in history. "This was the exact commit we used for this version on that rainy thursday when the build server broke". If you use a branch instead of a tag, you can never know what exact commit you used. You only know "We released version 1.1.0 somewhere on this branch", unless you manually write down the exact hash for that commit, which is why you use tags in the first place :)

您可以使用标签来记录历史中的重要提交。“这是我们在那个下雨的星期四构建服务器崩溃时用于此版本的确切提交”。如果您使用分支而不是标签,您将永远无法知道您使用的确切提交。您只知道“我们在此分支的某个地方发布了 1.1.0 版”,除非您手动写下该提交的确切哈希值,这就是您首先使用标签的原因:)

回答by Region39

In addition to the other answers, here is my 2 cents.

除了其他答案,这是我的 2 美分。

Short Answer:Use tags for release versions

简短回答:为发布版本使用标签

Long Answer:I believe using tags for release versioning specifically is better than using branches. If you need to update the relase, simply branch off of the tagged commit and once you finish working on that branch (most likely a hotfix branch), create a new tag at the head of that new branch with the new version. Then, merge that branch back into master/develop because you really shouldn't be changing a release version unless it's a hotfix that likely should be merged back into your source code. Then delete that branch since it's no longer needed. If you need to apply another hotfix to that new version, repeat the same steps.

长答案:我相信使用标签进行发布版本控制比使用分支更好。如果您需要更新版本,只需从标记的提交中分支出来,一旦您完成该分支(很可能是一个修补程序分支)上的工作,就在该新分支的头部使用新版本创建一个新标记。然后,将该分支合并回 master/develop,因为您真的不应该更改发布版本,除非它是一个可能应该合并回源代码的修补程序。然后删除该分支,因为不再需要它。如果您需要将另一个修补程序应用到该新版本,请重复相同的步骤。

Refer to the section of the following article that shows how to merge a hotfix with the author's Git workflow - https://hackernoon.com/a-branching-and-releasing-strategy-that-fits-github-flow-be1b6c48eca2

请参阅以下文章中展示如何将修补程序与作者的 Git 工作流程合并的部分 - https://hackernoon.com/a-branching-and-releasing-strategy-that-fits-github-flow-be1b6c48eca2