前言
Git分支详解参考:
https://blog.csdn.net/su1573/article/details/91988523
一、idea使用git 合并分支
1. 将主分支(master)更新到自己的分支(dev)
-
1、idea右下角点击分支、checkout到自己分支下、点击自己的分支、选择 remote branches 中的 origin/master 分支,点击 "merge selected into current"
-
2、checkout到自己分支下、点击Git/Pull、选择 origin/master 分支、点击Pull
两种方法都可。
2. 将自己的分支(dev)合并到主分支(master)
- 1、checkout到主分支(master)、先Pull一下最新的代码、点击右下角主分支、在local branches里选择自己的分支点击"merge selected into current"、然后记得push下、推送至远程仓库。
二、图文
2.1、切换分支
2.1.1、在idea页面右下角点击分支名

2.1.2、在git 分支选择框中选择项目一步步选择需要的分支
- 这里先演示切换到master主干分支,点击Checkout切换

2.1.3、切换master主干分支成功

2.2、合并分支
2.2.1、master合并bug001分支
- 2.2.1.1、拉取分支步骤:在项目上右键,Git -> Repository -> Pull

- 2.2.1.2、在更新代码的时候,选择001分支代码,合并到当前分支master,点击Pull

- 2.2.1.3、更新结果,显示37个文件已更新

- 2.2.1.4、从001分支更新代码到当前分支master后,已存到本地仓库,因此需要把本地仓库完整的master分支代码Push到远程分支master分支;Git -> Repository -> Push

- 2.2.1.5、点击Push后,出现详细的推送说明,点击Push

2.2.2、develop合并master分支
- 2.2.2.1、切换develop分支,原则上develop分支的代码必须和master主干保持一致

- 2.2.2.2、拉取分支步骤:在项目名上右键,Git -> Repository -> Pull,参考2.2.1.1
先更新远程develop分支到本地,看看有没有需要更新的代码,有的话直接更新

- 2.2.2.3、显示 no items,说明没有需要更新的代码

- 2.2.2.4、master分支已经最新的,因此需要把master分支代码合并到develop分支
Git -> Repository -> Pull,选择master分支代码,合并到当前分支develop,点击Pull

更新结果为37文件

- 2.2.2.5、把本地仓库develop分支的代码提交到远程分支develop;Git -> Repository -> Push

显示Push成功

2.2.3、Hebei合并develop分支
- 2.2.3.1、切换Hebei分支

切换成功

- 2.2.3.2、更新本分支代码,拉取分支步骤:在项目名上右键,Git -> Repository -> Pull,参考2.2.1.1


- 2.2.3.3、合并develop分支代码到当前分支hebei; Git -> Repository -> Pull

- 2.2.3.4、更新时出现冲突文件(20200604 更新,内容是最新的,和上面develop分支内容已不一致)
- 解决冲突:选中文件,点击右侧的Merge…

- 2.2.3.5、冲突文件界面解释
冲突文件界面,分为三个部分,最左侧是本地代码、中间是解决冲突后的最终结果文件、最右侧是远程分支的代码
通过比较文件内容,合并需要的代码到中间的位置,最后点击Apply就完成了
解决步骤如下:







- 2.2.3.6、因为在合并develop分支代码到当前分支hebei 时出现冲突,并且解决冲突后,需要先把代码提交到本地仓库,再把本地仓库的代码提交到远程分支。
右击项目名:
Git-> Commit Directory…
填写适当地 提交信息,然后点击Commit and Push
Commit and Push解释:
先把本地代码提交到了本地仓库,然后等待片刻会自动弹出Push的窗口,再把本地仓库代码推到远程


- 2.2.3.7、查看提交信息,然后点击Push,即可把代码提交到远程分支。

参考:
https://www.cnblogs.com/name-lizonglin/p/14613973.html
网友评论