git 用git合并多个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5292184/
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
Merging multiple branches with git
提问by Chvanikoff
I have 2 local branches called "develop" and "master"; they are similar. On my company's server there's one "main" repo (production) and several branches that were made by other developers:
我有 2 个名为“develop”和“master”的本地分支;他们很相似。在我公司的服务器上有一个“主”存储库(生产)和其他开发人员制作的几个分支:
$ git branch -a * develop master remotes/origin/HEAD -> origin/master remotes/origin/some-test remotes/origin/feature1 remotes/origin/feature2 remotes/origin/master
How can I merge remotes/origin/feature1
and remotes/origin/feature2
into my local "master" branch, copy that all into "develop" and start working with actual code in my "develop" branch?
如何合并remotes/origin/feature1
并remotes/origin/feature2
进入我的本地“master”分支,将所有内容复制到“develop”并开始在我的“develop”分支中使用实际代码?
回答by Cameron Skinner
git checkout master
git pull origin feature1 feature2
git checkout develop
git pull . master
(or maybegit rebase ./master
)
git checkout master
git pull origin feature1 feature2
git checkout develop
git pull . master
(或者也许git rebase ./master
)
The first command changes your current branch to master
.
第一个命令将您当前的分支更改为master
.
The second command pulls in changes from the remote feature1
and feature2
branches. This is an "octopus" merge because it merges more than 2 branches. You could also do two normal merges if you prefer.
第二个命令从远程feature1
和feature2
分支中提取更改。这是一个“章鱼”合并,因为它合并了 2 个以上的分支。如果您愿意,也可以进行两次普通合并。
The third command switches you back to your develop
branch.
第三个命令将您切换回您的develop
分支。
The fourth command pulls the changes from local master
to develop
.
第四个命令将更改从本地拉取master
到develop
.
Hope that helps.
希望有帮助。
EDIT: Note that git pull
will automatically do a fetch
so you don't need to do it manually. It's pretty much equivalent to git fetch
followed by git merge
.
编辑:请注意,这git pull
将自动执行,fetch
因此您无需手动执行。它几乎等同于git fetch
后跟git merge
。
回答by Brandon
I would just "fetch" all of origin:
我只想“获取”所有来源:
git fetch origin
now that it is in your repo you can merge the branches into master:
现在它在你的仓库中,你可以将分支合并到 master 中:
git checkout master
git merge origin/feature1
git merge origin/feature2
now you can merge master into develop
现在您可以将 master 合并到 develop
git checkout develop
git merge master
if you are going to commit back to origin then I would setup a local tracking branch so you can have local access and push directly to origin:
如果您要提交回原点,那么我将设置一个本地跟踪分支,以便您可以进行本地访问并直接推送到原点:
git branch --track origin/feature1 feature1