什么是 git 主题分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/284514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:57:33  来源:igfitidea点击:

What is a git topic branch?

gitversion-controlbranch

提问by skiphoppy

What is a git topic branch? Does it differ from an ordinary branch in some way? Are there any branches that are not topic branches?

什么是 git 主题分支?它在某些方面与普通分支不同吗?是否有任何分支不是主题分支?

采纳答案by Greg Hewgill

Topic branches are typically lightweight branches that you create locally and that have a name that is meaningful for you. They are where you might do work for a bug fix or feature (they're also called feature branches) that is expected to take some time to complete.

主题分支通常是您在本地创建的轻量级分支,并且具有对有意义的名称。它们是您可能会为预计需要一些时间才能完成的错误修复或功能(它们也称为功能分支)工作的地方。

Another type of branch is the "remote branch" or "remote-tracking branch". This type of branch follows the development of somebody else'swork and is stored in your own repository. You periodically update this branch (using git fetch) to track what is happening elsewhere. When you are ready to catch up with everybody else's changes, you would use git pullto both fetch and merge.

另一种类型的分支是“远程分支”或“远程跟踪分支”。这种类型的分支遵循其他人的工作开发并存储在您自己的存储库中。您定期更新此分支(使用git fetch)以跟踪其他地方发生的情况。当您准备好赶上其他人的更改时,您将同时使用git pullfetch 和 merge。

I have also seen another kind of branch which is essentially a completely separate tree of files in the same repository. For example, the Git repository itselfcontains heads named manand htmlthat contain entirely different content from the masterbranch. I don't know what these types of branches are usually called.

我还看到了另一种分支,它本质上是同一存储库中完全独立的文件树。例如,Git 存储库本身包含名为manhtml 的头,它们包含与master分支完全不同的内容。我不知道这些类型的分支通常被称为什么。

回答by mipadi

It's not a technical term; it just refers to a branch that was created to implement a specific feature or fix a bug. The "topic" is the reason for the creation of the branch, essentially.

这不是一个技术术语;它只是指为实现特定功能或修复错误而创建的分支。“主题”本质上是创建分支的原因。

回答by Jeff Ancel

https://github.com/dchelimsky/rspec/wiki/Topic-Branchesexplains this well:

https://github.com/dchelimsky/rspec/wiki/Topic-Branches很好地解释了这一点:

A “topic” branch is a separate branch that you use when working on a single “topic” (a bug fix, a new feature, or an experimental idea). Working on a topic branch instead of directly on top of “master” is recommended because:

{... visit link ...}

So, for all of these reasons it's recommended to use a topic branch for preparing submissions even for simple contributions like single-commit bugfixes and the like.

“主题”分支是您在处理单个“主题”(错误修复、新功能或实验性想法)时使用的单独分支。建议在主题分支上工作而不是直接在“master”之上工作,因为:

{...访问链接...}

因此,出于所有这些原因,建议使用主题分支来准备提交,即使是简单的贡献,例如单次提交错误修复等。

This sample also gives examples. Which actually got me to thinking, this is probably what most shops do already. All of the agile projects I've ever been with do. I upvoted th "It's not a technical term" because I feel this hits the nail on the head.

此示例还提供了示例。这实际上让我想到,这可能是大多数商店已经在做的事情。我参与过的所有敏捷项目都是如此。我赞成“这不是一个技术术语”,因为我觉得这很重要。

回答by Paul

it looks like the most prominent and important type of branches that aren't topic branches would be release branches on a major, publicly-available repository, right?

看起来不是主题分支的最突出和最重要的分支类型将是主要的公开可用存储库上的发布分支,对吗?

That's probably right for you, but that's about you and the project you're thinking about; it's not determined by Git.

这可能适合你,但那是关于你和你正在考虑的项目;它不是由 Git 决定的。

Most version control systems (particularly centralized ones) prescribe or enforce a particular workflow, including what it makes sense to use a branch for. Git ( and to some extent most distributed VCSs) consider that workflow, what branches are used for, when to commit, what different repos are used for, etc. is all chosen by the users and agreements among the users (policies). So Git doesn't enforce these technically.

大多数版本控制系统(特别是集中式的)规定或强制执行特定的工作流程,包括使用分支的意义。Git(以及在某种程度上大多数分布式 VCS)认为工作流、分支用于什么、何时提交、不同的存储库用于什么等都是由用户选择的,以及用户之间的协议(策略)。所以 Git 在技术上没有强制执行这些。

This is one of the things that made Git hard for me to learn. Oliver Steele explained this from user's view, writing about Commit Policies.

这是让我难以学习 Git 的原因之一。Oliver Steele 从用户的角度解释了这一点,撰写了关于Commit Policies 的文章