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
How does a Git repository works with a develop and master branch?
提问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 master
and develop
. So I went ahead and created a repository. However, to my surprise, the repository itself was the default master
branch. How was I supposed to create a develop
branch? Do I create it in the parent of the master
branch? That would mean that the develop
branch is outside the repository.
它说存储库有 2 个主要分支,称为master
和develop
。所以我继续创建了一个存储库。然而,令我惊讶的是,存储库本身是默认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 master
branch, rather master
and develop
will both initially label the same commit.
分支不是目录。它是一个随提交一起移动的提交标签,就像 tag 是一个与特定提交保持一致的提交标签。你不会有任何“内部”的master
分支,而master
与develop
将在初始标注相同的承诺。
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 master
branch.
澄清一下:假设您有初始提交 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 master
won'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 master
branch is created by default; you can think of it like the "trunk" in other VCS systems. The develop
branch used in the nvie branching model branches from master
, presumably from the first commit.
该master
分支是默认创建的; 你可以把它想象成其他 VCS 系统中的“主干”。的develop
在nvie分支模型分支用于从分支master
从,大概是第一次提交。
The develop
branch is a normal branch off of master
.
该develop
分支是 的正常分支master
。
git branch develop
creates the develop
branch.
git branch develop
创建develop
分支。
In the nvie branching model, all development work is done on the develop
branch 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 master
and tag when the code is ready to be released.
在 nvie 分支模型中,所有开发工作都在develop
分支上完成,只有在代码准备好发布时才合并到 master 并在那里标记。许多人使用的典型工作流程只是master
在代码准备发布时提交所有开发并标记。