git - 标签与 Git 中的分支有何不同?我应该在这里使用哪个?

标签 git version-control branch git-branch git-tag

我在理解如何在 中使用标签分支 时遇到了一些困难。 .

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

最佳答案

理论的角度来看:

  • 标签 是给定修订 的符号名称。他们总是指向同一个对象(通常:指向同一个版本);他们不会改变。
  • 分支开发线的符号名称。新提交是在分支之上创建的。分支指针自然前进,指向越来越新的提交。

技术的角度来看:

  • 标签位于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/

相关文章:

php - Travis CI 构建 PHP 项目并从 Composer 中提取依赖项,尝试使用 git@ 而不是 https

git - 在新分支中使用挂起的分支更改的正确过程

ruby-on-rails - 如何使用 bundler 强制更新 gem?

GitHub 页面只显示自述文件?

python - docker 容器中显示的旧版本代码

没有经验的成员的 Git 工作流程

git - 在 Git 中重新定位远程分支

git - 重写历史记录以删除重复的提交消息

git delete branch with name 包含特殊字符

git - 更改 git 中的分支会导致更改的文件