我有一些困难理解如何使用标签与分支在git。

我只是将当前版本的代码从cvs移到git,现在我将针对特定的特性处理该代码的一个子集。其他一些开发人员也将致力于此,但并不是我们团队中的所有开发人员都会关心此功能。我应该创建一个分支还是一个标签?在什么情况下我应该使用其中一种而不是另一种?


当前回答

从理论角度看:

标签是给定修订的符号名称。它们总是指向相同的对象(通常是:指向相同的修订);它们不会改变。 分支是开发线的象征性名称。在分支的顶部创建新的提交。分支指针自然地向前移动,指向越来越新的提交。


从技术角度看:

tags reside in refs/tags/ namespace, and can point to tag objects (annotated and optionally GPG signed tags) or directly to commit object (less used lightweight tag for local names), or in very rare cases even to tree object or blob object (e.g. GPG signature). branches reside in refs/heads/ namespace, and can point only to commit objects. The HEAD pointer must refer to a branch (symbolic reference) or directly to a commit (detached HEAD or unnamed branch). remote-tracking branches reside in refs/remotes/<remote>/ namespace, and follow ordinary branches in remote repository <remote>.


参见gitglossary manpage:

branch A "branch" is an active line of development. The most recent commit on a branch is referred to as the tip of that branch. The tip of the branch is referenced by a branch head, which moves forward as additional development is done on the branch. A single git repository can track an arbitrary number of branches, but your working tree is associated with just one of them (the "current" or "checked out" branch), and HEAD points to that branch. tag A ref pointing to a tag or commit object. In contrast to a head, a tag is not changed by a commit. Tags (not tag objects) are stored in $GIT_DIR/refs/tags/. [...]. A tag is most typically used to mark a particular point in the commit ancestry chain. tag object An object containing a ref pointing to another object, which can contain a message just like a commit object. It can also contain a (PGP) signature, in which case it is called a "signed tag object".

其他回答

简单:

标签总是指向项目的同一个版本,而头部则随着开发的进展而变化。

Git用户手册

我喜欢把分支看作你要去的地方,标签看作你去过的地方。

标记就像过去某个特定重要点的书签,比如版本发布。

而分支是项目前进的特定路径,因此分支标记会随着您一起前进。当你完成时,你合并/删除分支(即标记)。当然,在这一点上,您可以选择标记该提交。

我们使用

开发环境中的分支用于特性开发或错误修复 功能分支上测试环境的轻量级标记 release/prd的注释标记(主要分支)

在每个带注释的标签之后,所有的特征分支都从主分支中重新建立基础。

正如其他人所说,分支是一条开发线,随着更新提交的到来,头部会向前移动。这是功能开发的理想选择。

轻量级标签固定于特定的提交,这使得创建内部版本并让qa团队在开发完成后测试功能成为理想的选择。

注释标记非常适合从发布到生产,因为我们可以在将测试的特性分支合并到主分支(稳定)时添加正式的消息和其他注释。

标签可以是有符号的,也可以是无符号的;分支从不签名。

有签名的标记永远不能移动,因为它们以加密方式(使用签名)绑定到特定的提交。Unsigned标签是不绑定的,可以移动它们(但是移动标签不是一个正常的用例)。

分支不仅可以移动到不同的提交,而且还可以这样做。您应该为本地开发项目使用分支。“在标记上”将工作提交到Git存储库是没有意义的。

树枝是木头做的,从树干上长出来。标签由纸(木材的衍生品)制成,像圣诞装饰品一样挂在树上的各个地方。

您的项目是树,您将添加到项目中的特性将在分支上生长。答案是分支。