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

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


当前回答

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

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

其他回答

简单的答案是:

分支机构: 每次提交到存储库时,当前分支指针都会移动

but

标签:标签指向的提交没有改变,事实上标签是该提交的快照。

从理论角度看:

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


从技术角度看:

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".

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

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

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

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

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

最好的解释似乎是标签充当只读分支。您可以使用分支作为标记,但您可能会无意中使用新的提交更新它。只要标签存在,它们就保证指向相同的提交。