Git 存储库如何与开发和主分支配合使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6210272/
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 11:04:06  来源:igfitidea点击:

How does a Git repository works with a develop and master branch?

git

提问by John Godspeed

I'm new to Git and this is really confusing. I wanted to start off developing a web application on Git and so far I've been dealing with troubles that have kept me behind.

我是 Git 的新手,这真的很令人困惑。我想开始在 Git 上开发一个 Web 应用程序,到目前为止我一直在处理让我落后的麻烦。

I've read this blogpost on a successful branching model for Git. I was really interested in setting up something similar to this.

我已经阅读了这篇关于 Git 成功分支模型的博客文章。我真的对设置类似的东西很感兴趣。

It says that the repository has 2 main branches called masterand develop. So I went ahead and created a repository. However, to my surprise, the repository itself was the default masterbranch. How was I supposed to create a developbranch? Do I create it in the parent of the masterbranch? That would mean that the developbranch is outside the repository.

它说存储库有 2 个主要分支,称为masterdevelop。所以我继续创建了一个存储库。然而,令我惊讶的是,存储库本身是默认master分支。我应该如何创建一个develop分支?我是否在master分支的父级中创建它?这意味着develop分支在存储库之外。

Am I getting something totally wrong here? Do I just ignore the fact that I'm creating two branches inside the master branch?

我在这里完全错了吗?我是否只是忽略了我在 master 分支内创建两个分支的事实?

回答by Amadan

A branch is not a directory. It is a commit label that moves along with commits, like tag is a commit label that stays with a particular commit. You will not have anything "inside" the masterbranch, rather masterand developwill both initially label the same commit.

分支不是目录。它是一个随提交一起移动的提交标签,就像 tag 是一个与特定提交保持一致的提交标签。你不会有任何“内部”的master分支,而masterdevelop将在初始标注相同的承诺。

Create the develop branch like so:

像这样创建开发分支:

git branch develop

To clarify: let's say you have the initial commit A. It will be labeled as masterbranch.

澄清一下:假设您有初始提交 A。它将被标记为master分支。

git init

A [master]

If you make a new commit B, the branch label will move:

如果您进行新的提交 B,则分支标签将移动:

git commit -a

A -> B [master]

If you then branch into develop, the B will get the new label as well:

如果然后分支到develop,B 也将获得新标签:

git branch develop

A -> B [master, develop]

If you commit on the develop, it will move, but masterwon't:

如果您提交develop,它将移动,但master不会:

git checkout develop
git commit -a

A -> B [master] -> C [develop]

If you now commit on the master, the tree will fork:

如果您现在提交master,则树将分叉:

git checkout master
git commit -a

A -> B -> C [develop]
     +--> D [master]

Meanwhile, you only have in your directory whatever the contents of your current commit is. Switch branches, and the directory contents change.

同时,您的目录中只有当前提交的内容。切换分支,目录内容改变。

回答by Ken Liu

The masterbranch is created by default; you can think of it like the "trunk" in other VCS systems. The developbranch used in the nvie branching model branches from master, presumably from the first commit.

master分支是默认创建的; 你可以把它想象成其他 VCS 系统中的“主干”。的develop在nvie分支模型分支用于从分支master从,大概是第一次提交。

The developbranch is a normal branch off of master.

develop分支是 的正常分支master

git branch developcreates the developbranch.

git branch develop创建develop分支。

In the nvie branching model, all development work is done on the developbranch and only merged to master and tagged there when the code is ready to be released. The typical workflow that many people use is just to commit all development to masterand tag when the code is ready to be released.

在 nvie 分支模型中,所有开发工作都在develop分支上完成,只有在代码准备好发布时才合并到 master 并在那里标记。许多人使用的典型工作流程只是master在代码准备发布时提交所有开发并标记。