Day 5 : Git 多人协作

开分支

具体上要开那些branch呢? 我习惯大致简化分成三种

  • master 上到production的版本,没把握不要改动他
  • develop 开发版,开发过程的主要干线,让feature去修改他
  • feature/人 团队的个人开发,开发一个段落merge到develop版

https://ithelp.ithome.com.tw/upload/images/20210906/20119044vgU4DIm7iA.png

如上图,团队主要开发分支会在develop上。每天早晨主管核对完每个人的任务後,每个人会各自开发她们的feature,如人物(b1)开发feature/b1,人物(b2)开发feature/b2。完成自己的任务,或是快下班了,再将今天开发的东西merge给develop,当develop开发成熟後,就可以将develop merge给master,完成这一次的版本更新。

详细参考: https://nvie.com/posts/a-successful-git-branching-model/

Merge

Feature开发完成後要并回develop,首先我们要先知道是谁合并谁。merge合并就像是吸收的动作,git status看一下现在处於哪个分支,并且要吸收掉哪个其他分支。

# 想要develop merge掉feature/b1
# 先切换到develop
git checkout develop

# 合并
git merge --no-ff feature/b1

# --no-ff是合并後分支保留的意思

如果没有加上--no-ff默认会把被合并的分支消灭,所以加上让feature/b1继续走下去。如下图,成功合并。
https://ithelp.ithome.com.tw/upload/images/20210906/20119044inGeS7PSQX.png

假如今天feature/b2也修改了同一个档案,并且尝试给develop merge呢?会产生冲突

git merge --no-ff feature/b2
# 喷错
# Auto-merging Apple.txt
# CONFLICT (content): Merge conflict in Apple.txt
# Automatic merge failed; fix conflicts and then commit the result

此时进入人工调整merge的时候,此时visual studuio会自动侦测那些地方有冲突,你必须手动去修改这些冲突。点选incomming(要变的)还是accept current (保留原始code)

https://ithelp.ithome.com.tw/upload/images/20210906/20119044SJLqYGp5cx.png\

决定後保存并commit,并且切换到b2,换他merge develop来同步最新的更新

git commit -am "合并b2"
git checkout feature/b2
git merge --no-ff develop

# 将这次的改变推上远端仓库
git checkout develop
git push origin develop

https://ithelp.ithome.com.tw/upload/images/20210906/20119044u6ZyNZG0Mc.png

可以看到红色为develop主干道,feature/b1(绿色)与feature/b2(蓝色) 对develop进行merge,merge完後再继续进行开发。 (如果没有--no-ff分支会消失)


pull requests

简单讲一下正常的CI/CD软件开发流程,通常开发人员不允许直接merge到master:

  1. 多人开设feature 对develop进行开发
  2. 当develop开发到一定版本後会进行pull requests到master(要求将develop的内容merge给master)。
  3. 通常master只有专案主管有权限修改,避免太多修改导致混乱。
  4. 专案技术主管省查develop的code後允许merge,(master) git merge develop
  5. master branch受到变动,因此启用CI/CD流程,将会自动将master的程序部属到production机器上

下面来讲一下怎麽pull request,其实github点一点就好。

https://ithelp.ithome.com.tw/upload/images/20210907/20119044ioNF1Xa28T.png

此时Project Owner就会收到pull request的请求。点选merge pull requests即可。

https://ithelp.ithome.com.tw/upload/images/20210907/20119044UTbyGyQS5g.png


<<:  Tcl语言和你 SAY HELLO!!

>>:  [Day6] 呼吸灯制作

[重构倒数第12天] - Vue3 directive 与 Skeleton 实战组合应用

前言 该系列是为了让看过Vue官方文件或学过Vue但是却不知道怎麽下手去重构现在有的网站而去规画的系...

Day 15【web3.js】一袋米要扛几楼

【前言】 这两天的文章都是 web3.js 的学习笔记,大部分内容都来自他们的官方文件!之後还会有...

Re: 新手让网页 act 起来: Day30 - React hooks 之 useDebugValue

前言 今天要介绍最後一个 React hook - useDebugValue ,它也是个较少使用的...

Python 入门笔记

前言 : Python 是一门相对比较好上手的程序语言,简洁的表述与直觉的语句使许多人易於上手;笔者...

劫持用户会话(hijack user sessions)

-VLAN组(来源:Cisco Press) VLAN是一种创建其广播域的网络分段和隔离机制。路由...