用git合并多个分支 [英] Merging multiple branches with git

查看:520
本文介绍了用git合并多个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个本地版本库叫做develop和master;他们是相似的。在我公司的服务器上,有一个主回购(生产)和其他开发人员创建的几个分支:

 
$ git branch -a
* develop
master
遥控器/ origin / HEAD - > origin / master
遥控器/原点/某些测试
遥控器/原点/特性1
遥控器/ origin / feature2
remotes / origin / master

如何合并 remotes / origin / feature1 remotes / origin / feature2 放入我的本地master仓库,将其全部复制到develop中,并开始使用我的开发回购?

解决方案


  1. git checkout master
  2. git pull origin feature1 feature2

  3. git checkout开发

  4. git pull。 master (或者 git rebase ./master

第一条命令将当前分支更改为 master

第二条命令从远程 feature1 feature2 分支。这是一个章鱼合并,因为它合并了两个以上的分支。如果您愿意的话,您也可以进行两次正常的合并。


第三个命令将您切换回您的 develop 分支。

第四个命令将更改从本地 master 拉到开发

希望有帮助。

编辑:请注意, git pull 会自动执行 fetch ,所以你不需要手动执行。它几乎等同于 git fetch ,接着是 git merge


I have 2 local repositories called "develop" and "master"; they are similar. On my company's server there's 1 "main" repo (production) and several branches that were made by other developers:

$ 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" repo, copy that all into "develop" and start working with actual code in my "develop" repo?

解决方案

  1. git checkout master
  2. git pull origin feature1 feature2
  3. git checkout develop
  4. git pull . master (or maybe git rebase ./master)

The first command changes your current branch to 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.

The third command switches you back to your develop branch.

The fourth command pulls the changes from local master to 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合并多个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆