gitlab --分支管理

  1. 创建新分支
    git branch first-branch

  2. 切换到新分支
    git checkout first-branch

  3. 创建新分支并切换到新创建的分支
    git checkout -b first-branch

  4. 创建文件
    echo “change” >> test.md

  5. 手动add 该文件
    git add test.md ## 如果没有该步骤则报错,提示commit nothing

  6. commit 注释
    git commit -a -m “first branch”

  7. 推送分支到gitlab
    git push -u origin master ## 此时可在web gitlab上看到多了一个分支

  8. 切换到master
    git checkout master

  9. 合并分支 first-branch 到master分支 ##此时可查看主分支多了合并的代码
    git merge first-branch --no-ff

  10. 删除分支
    git push origin -d first-branch

11 合并冲突模拟(手动合并)
注意:只有同目录同文件同行才会造成合并冲突的情况,只要有一点不同就能够进行合并

01.准备:

1 cd git_data
2 echo 'master code' >>README
3 git commit -a -m 'this master branch commit'
4 git checkout linux
5 cat README
6 
7 echo 'linux code' >>README
8 git commit -a -m 'this linux branch second commit'
9 git checkout master
02.现象:

1 [root@gitlab git_data]# git merge linux
2 Auto-merging README   ->自动合并 README
3 CONFLICT (content):Merge conflict in README   ->冲突(内容):合并冲突于 READM
4 Automatic merge failed; fix conflicts and then commit the result.
5 ->自动合并失败;修正冲突然后提交修正的结果

03.解决:人工选择想要的内容,同时修改master和linux分支同文件并提交,最后merge

复制代码
1 [root@gitlab git_data]# vim README
2 this is linux branch hello world
3 master code
4 linux code
5 [root@gitlab git_data]# git commit -a -m '解决合并冲突'
6 [master 19cb918] 解决合并冲突
7 [root@gitlab git_data]# git merge linux
8 Already up-to-date.

参考:
https://blog.csdn.net/zangxueyuan88/article/details/81078879 --分支管理
https://www.cnblogs.com/bananaaa/p/7975598.html --手动合并

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值