Python全栈(六)项目前导之5.使用GitHub进行多人协同开发

一、rebase的使用

rebase可以保持提交记录简洁,不分叉。
热巴瑟的主要用法有:

  • 合并多个commit为一个完整commit
  • 将某一段commit粘贴到另一个分支上

其中第一种用法为git rebase -i HEAD~NUM
假设现已开发了四个版本,现需要将后三个合并,可以操作如下:

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase
$ git init
Initialized empty Git repository in E:/Test/pro_rebase/.git/

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ touch 1.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git add .

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git commit -m 'v1'
[master (root-commit) 14ba83e] v1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git log
commit 14ba83ee063f927cc11826188651d684424277af (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:30 2020 +0800

    v1

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ touch 2.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git add .

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git commit -m 'v2'
[master b1ce2da] v2
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 2.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git log
commit b1ce2da891238d6694c5e0853e300272403479b8 (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:56 2020 +0800

    v2

commit 14ba83ee063f927cc11826188651d684424277af
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:30 2020 +0800

    v1

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ touch 3.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git add .

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git commit -m 'v3'
[master b076bba] v3
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 3.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git log
commit b076bba0c3948ce15fe40b31ce04e86074d91641 (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:05:45 2020 +0800

    v3

commit b1ce2da891238d6694c5e0853e300272403479b8
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:56 2020 +0800

    v2

commit 14ba83ee063f927cc11826188651d684424277af
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:30 2020 +0800

    v1

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ touch 4.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git addd .
git: 'addd' is not a git command. See 'git --help'.

The most similar command is
        add

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git add .

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git commit  -m 'v4'
[master 08fd4d1] v4
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 4.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git log
commit 08fd4d139d53972ab0a12a3e43bfabd371653d22 (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:06:27 2020 +0800

    v4

commit b076bba0c3948ce15fe40b31ce04e86074d91641
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:05:45 2020 +0800

    v3

commit b1ce2da891238d6694c5e0853e300272403479b8
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:56 2020 +0800

    v2

commit 14ba83ee063f927cc11826188651d684424277af
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:30 2020 +0800

    v1

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git rebase -i HEAD~3
[detached HEAD fc3a407] v2 & v3 & v4
 Date: Tue Mar 31 10:04:56 2020 +0800
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 2.py
 create mode 100644 3.py
 create mode 100644 4.py
Successfully rebased and updated refs/heads/master.

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/pro_rebase (master)
$ git log
commit fc3a407e30eebff4c4540dc699c823ea4b63d1c5 (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:56 2020 +0800

    v2 & v3 & v4

commit 14ba83ee063f927cc11826188651d684424277af
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:04:30 2020 +0800

    v1


二、多人协同开发工作流

多人开发工作流思路如下:
多人协同开发工作流思路

1.创建组织和项目

  • 创建项目目录
mkdir xxx
  • 基本版本开发
touch app.py
git add .
git commit -m 'basicversion'
  • 创建组织
  • 创建组织下的仓库
    创建组织和仓库的示例如下:
    Github组织和仓库创建
  • 推送代码到组织下的仓库
git remote add origin xxx
git push origin master

创建之后得到的基础版本如下:
基本版本

  • 给版本打标签
git tag -a v1-m 'xxx'
git push origin --tags # 推送标签

测试如下:

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test
$ mkdir multi

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test
$ cd multi/

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi
$ git init
Initialized empty Git repository in E:/Test/multi/.git/

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ touch app.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git add .

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git commit -m '基本版本'
[master (root-commit) ef92c45] 基本版本
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 app.py

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git log
commit ef92c4505df01fd99a3cdf3b5f4c7e1ab2064572 (HEAD -> master)
Author: Corley <[email protected]>
Date:   Tue Mar 31 10:37:34 2020 +0800

    基本版本

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git remote add origin [email protected]:multidevtest/test_pro.git

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 217 bytes | 108.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:multidevtest/test_pro.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git tag -a v1 -m 'v1tag'

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git push -u origin --tags
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 155 bytes | 155.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To github.com:multidevtest/test_pro.git
 * [new tag]         v1 -> v1

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git push origin --tags
Everything up-to-date

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (master)
$ git checkout -b dev
Switched to a new branch 'dev'

Lenovo@LAPTOP-61GNF3CH MINGW64 /e/Test/multi (dev)
$ git branch
* dev
  master

2.邀请成员

协同开发时,需要所有成员都可以对同一个项目进行操作,需要邀请成员并赋予权限,否则无法开发。
github支持两种创建项目的方式供多人协同开发:

  • 添加合作者
    将用户添加到仓库合作者中之后,该用户就可以向当前仓库提交代码。
  • 创建组织
    将成员邀请进入组织,组织下可以创建多个仓库,组织成员可以向组织下仓库提交代码。
    被邀请者默认对组织中的项目具有读权限,要想其可以开发项目,需要给予其写的权限。

邀请成员的操作如下:
邀请成员

3.成员开发

  • 成员克隆代码并进行开发
mkdir xxx
git clone xxx
git checkout -b devc1
touch c1.py
  • 上交代码
git add .
git commit -m 'xxx'
git push origin devc1

4.代码审查(code review)

  • 组长创建规则
    示例如下:
    GitHub create rule
  • 成员提交code review申请(New pull request
    成员 new pull request
  • 组长检查代码(code review)

5.提测上线(预发布)

专门团队或项目leader执行以下步骤:

  • 基于dev分支创建release分支
git checkout dev 
git checkout -b release
  • 测试,DEBUG
  • 合并到master
    本地将release合并到master分支,并上传。
git checkout master
git merge release
git push origin master
  • 在master分支打tag
git tag -a v2 -m 'xxx' 
git push origin --tags

其他相关工作如下:

  • dev分支合并release分支,以保证是最新代码
git checkout dev
git merge release
  • 运维人员下载代码做上线工作
发布了97 篇原创文章 · 获赞 863 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/CUFEECR/article/details/105228791