我有一些困难理解如何使用标签与分支在git。
我只是将当前版本的代码从cvs移到git,现在我将针对特定的特性处理该代码的一个子集。其他一些开发人员也将致力于此,但并不是我们团队中的所有开发人员都会关心此功能。我应该创建一个分支还是一个标签?在什么情况下我应该使用其中一种而不是另一种?
我有一些困难理解如何使用标签与分支在git。
我只是将当前版本的代码从cvs移到git,现在我将针对特定的特性处理该代码的一个子集。其他一些开发人员也将致力于此,但并不是我们团队中的所有开发人员都会关心此功能。我应该创建一个分支还是一个标签?在什么情况下我应该使用其中一种而不是另一种?
当前回答
标记表示特定分支在某一时刻的版本。分支代表一个独立的开发线程,它可以与相同代码库上的其他开发工作同时运行。对一个分支的更改最终可能合并回另一个分支以统一它们。
Usually you'll tag a particular version so that you can recreate it, e.g., this is the version we shipped to XYZ Corp. A branch is more of a strategy to provide on-going updates on a particular version of the code while continuing to do development on it. You'll make a branch of the delivered version, continue development on the main line, but make bug fixes to the branch that represents the delivered version. Eventually, you'll merge these bug fixes back into the main line. Often you'll use both branching and tagging together. You'll have various tags that may apply both to the main line and its branches marking particular versions (those delivered to customers, for instance) along each branch that you may want to recreate -- for delivery, bug diagnosis, etc.
它实际上比这更复杂——或者像你想的那样复杂——但这些例子应该能让你了解其中的区别。
其他回答
从理论角度看:
标签是给定修订的符号名称。它们总是指向相同的对象(通常是:指向相同的修订);它们不会改变。 分支是开发线的象征性名称。在分支的顶部创建新的提交。分支指针自然地向前移动,指向越来越新的提交。
从技术角度看:
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".
简单的答案是:
分支机构: 每次提交到存储库时,当前分支指针都会移动
but
标签:标签指向的提交没有改变,事实上标签是该提交的快照。
最好的解释似乎是标签充当只读分支。您可以使用分支作为标记,但您可能会无意中使用新的提交更新它。只要标签存在,它们就保证指向相同的提交。
标记表示特定分支在某一时刻的版本。分支代表一个独立的开发线程,它可以与相同代码库上的其他开发工作同时运行。对一个分支的更改最终可能合并回另一个分支以统一它们。
Usually you'll tag a particular version so that you can recreate it, e.g., this is the version we shipped to XYZ Corp. A branch is more of a strategy to provide on-going updates on a particular version of the code while continuing to do development on it. You'll make a branch of the delivered version, continue development on the main line, but make bug fixes to the branch that represents the delivered version. Eventually, you'll merge these bug fixes back into the main line. Often you'll use both branching and tagging together. You'll have various tags that may apply both to the main line and its branches marking particular versions (those delivered to customers, for instance) along each branch that you may want to recreate -- for delivery, bug diagnosis, etc.
它实际上比这更复杂——或者像你想的那样复杂——但这些例子应该能让你了解其中的区别。
github上的Neovim:
V0.3是一个分支
v0.3.1……v0.3.4……是标签
Nightly和stable是标记,而不是分支