Git 中的分支是什么?

发布于 2024-10-09 15:30:13 字数 72 浏览 0 评论 0原文

我有几个 Git 存储库,它们都有一个名为“master”的分支。但是什么是分支以及你可以用它们做什么呢?

谢谢。

I have several Git repositories that all have one branch called 'master.' But what are branches and what can you do with them?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

奢华的一滴泪 2024-10-16 15:30:13

当您想要在自己的环境中开发特定功能时,可以使用分支。这样您就不会将未经测试的代码与通常稳定的版本 trunk 混合在一起。您可以进行分支,直到开发并测试了该功能,然后将分支合并回主干。

Branches are used when you want to develop a specific feature in an environment for itself. It's so you don't mix untested code with trunk, the generally stable version. You branch until you have developed and tested the feature, then you merge the branch back into trunk.

喜爱皱眉﹌ 2024-10-16 15:30:13

分支通常是彼此独立的并行开发流。类似于时间线。 这里是具有多个分支的软件项目的图片。

例如,您可能有一个分支包含您所有的稳定工作,另一个分支包含实验工作。您可能在其间有另一个暂存分支,用于在将实验分支移动到稳定分支之前限定来自实验分支的更改。这些都是分支策略。不同的团队可能有不同的分支等。

根据您的版本控制系统,分支的实现和使用可能会有很大不同。在集中式版本控制系统(例如 SVN)中,分支本质上是分支时整个源代码的副本(类似于文件系统上的 cp -R )。之后,该分支将独立于主分支进行开发。所以你会得到类似这样的内容

--o---0---o---o---o---- (parent branch)
       \
        \---o---o---0--- (new branch)

o 表示提交,0 表示分支点。您使用此系统创建的分支是全局的(项目中的每个人都可以看到它们)并且它们非常重。当您需要时,可以将新分支合并回父分支。这可能会导致合并冲突

对于去中心化的 VC(我以 git 为例),分支 的作用要大得多轻的。它们只是指向 DAG 中代表项目历史的位置的指针。您可以通过创建新的提交来推动它们前进。此外,分支将是本地的(即只有您可以看到它们,除非您决定发布它们)。

但是,分支和合并有一些概念性内容,如果不阅读文档,您将无法弄清楚。我建议您查看正在使用的 VCS 的文档,如果有任何具体问题,请返回堆栈溢出并提出具体问题。

Branches are usually parallel streams of development independent from each other. Similar to a timeline. Here is a picture of a software project with multiple branches.

You might have a branch that contains all your stable work for example and another which contains experimental work. You might have another staging branch in between which is used to qualify changes from the experimental branch before moving it into the stable one. These are all branching strategies. Different teams might have different branches etc.

Depending on your version control system, the implementation and uses of branches might be vastly different. In centralised version control systems (e.g. SVN), a branch is essentially a copy of then entire source code at the time of branching (similar to a cp -R on a filesystem). After that, development will proceed on this branch independent on the main one. So you will have something like this

--o---0---o---o---o---- (parent branch)
       \
        \---o---o---0--- (new branch)

The o signifies a commit and the 0 is the point of branching. The branches you make with this system are global (everyone on your project can see them) and they're quite heavy. It is possible to merge the new branch back into the parent branch when you want. This might entail merge conflicts.

With decentralised VCs (I'm using git as an example), branches are much more lightweight. They're simply pointers to a position in the DAG that represents the history of your project. You can push them forward by creating a new commit. Also, the branches will be local (i.e. only you can see them unless you decide to publish them).

However, branching and merging has some conceptual content that you can't figure out without reading the docs. I'd suggest that you look at the documentation of the VCS you're using and come back on stack overflow with specific questions if you have any.

菊凝晚露 2024-10-16 15:30:13

这是一篇我喜欢一直参考的好文章:成功的 Git 分支模型

本文是一个与 Git 进行有效协作的团队的实际且成功的案例研究。

Here is a nice article that I like to refer to all the time: Successful Git Branching Model

The article is a practical and successful case study of a team who collaborate effectively with Git.

︶ ̄淡然 2024-10-16 15:30:13

由于您是 GIT 新手,我强烈建议您阅读本书的第 3 章:

http://progit.org/book/< /a>

我相信@Noufal 和@Jakob 已经给出了一个很好的答案。然而,当涉及到使用 GIT 的实际方面时,你总是会犯错误,因为分支的语法不同(master、origin master、origin/master 等)。

另外,我建议阅读 GIT 的概念,而不是如何要使用它,请检查此链接,您可能有兴趣阅读有关分支的信息:

http ://www.eecs.harvard.edu/~cduan/technical/git/

As you are new to GIT, I enthusiastically recommend read Chapter 3 in this book:

http://progit.org/book/

@Noufal and @Jakob already gave a good answer I believe. However, when it comes to the practical side of using GIT, you will always make mistakes, because of the different syntax of branches (master, origin master, origin/master, etc.

Also, I recommend reading the concepts of GIT rather than how to use it, so check this link and you might be interested in reading about branching:

http://www.eecs.harvard.edu/~cduan/technical/git/

ˇ宁静的妩媚 2024-10-16 15:30:13

作为对所提供答案的补充,有一个有关分支和合并的 git 网络广播 http://gitcasts.com/ 或直接访问 http://blip.tv/file/4094707代码>

complementing the provided answers, there is a git webcast regarding branching and merging over http://gitcasts.com/ or go directly to http://blip.tv/file/4094707

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文