我在理解如何在 git 中使用标签 与分支 时遇到了一些困难。 .
我刚刚从 cvs 移动了我们代码的当前版本至 git ,现在我将针对特定功能处理该代码的一个子集。其他一些开发人员也将致力于此,但并非我们小组中的所有开发人员都会关心此功能。我应该创建一个分支还是一个标签?在什么情况下我应该使用其中一种还是另一种?
最佳答案
从理论的角度来看:
- 标签 是给定修订 的符号名称。他们总是指向同一个对象(通常:指向同一个版本);他们不会改变。
- 分支是开发线的符号名称。新提交是在分支之上创建的。分支指针自然前进,指向越来越新的提交。
从技术的角度来看:
- 标签位于
refs/tags/
命名空间,并且可以指向标签对象(带注释的和可选的 GPG 签名标签)或直接指向提交对象(本地名称较少使用的轻量级标签),或者在极少数情况下甚至树对象或blob对象(例如GPG签名)。 - 分支机构位于
refs/heads/
命名空间,并且只能指向提交对象。HEAD
指针必须指向分支(符号引用)或直接指向提交(分离的 HEAD 或未命名的分支)。 - 远程跟踪分支 位于
refs/remotes/<remote>/
命名空间,并遵循远程存储库中的普通分支<remote>
.
另见 gitglossary手册页:
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.
标签
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.标记对象
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 - 标签与 Git 中的分支有何不同?我应该在这里使用哪个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1457103/