gitflow 工具使用

作者: 又是很难取名字的付小白 | 来源:发表于2017-07-13 12:14 被阅读176次

    一. git-flow 前情提要

    model:
    1. http://nvie.com/posts/a-successful-git-branching-model/
    2. http://nvie.com/files/Git-branching-model.pdf
    工具:
    1. 使用介绍:https://github.com/nvie/gitflow
    2. git-flow 安装:https://github.com/nvie/gitflow/wiki/Installation
    3. git-flow completion 安装:

    二. 代码库使用说明

    图形示例图

    五角星表示临时代码库,圆柱体表示远端代码库。
    原则上,master 和 develop 分支永远存在。

    image.png
    个人开发流程
    1. 初始流程

      > git flow init -f
          
      Which branch should be used for bringing forth production releases?
         - develop
         - master
         - rc9.2
      Branch name for production releases: [master] master
          
      Which branch should be used for integration of the "next release"?
         - develop
      Branch name for "next release" development: [develop] develop
          
      How to name your supporting branch prefixes?
      Feature branches? [feature/] feature
      Release branches? [release/] release
      Hotfix branches? [hotfix/] hotfix
      Support branches? [support/] support
      Version tag prefix? [v] v  
      
      1. git clone <user>@<ip addr>:<repo>
        从远端拉下代码分支 master 和 develop

      2. git flow init -d
        在该项目下建立 git flow 默认初始化配置

      3. git flow init -f
        重新配置 git flow,示例如下
        再次强烈建议使用 git bash completion,无惧复杂分支名

        • master 分支名: master
        • development 分支名: develop
        • feature 分支名:feature
        • release 分支名:release
        • hotfix 分支名:hotfix
        • support 分支名:support
        • version 标签前缀:v
    2. 开发流程

      > git flow feature start cs
      Switched to a new branch 'feature/cs'
      
      Summary of actions:
      - A new branch 'feature/cs' was created, based on 'develop'
      - You are now on branch 'feature/cs'
      
      Now, start committing on your feature. When done, use:
      
      git flow feature finish cs
      
      > git flow feature finish cs
      Switched to branch 'develop'
      Your branch is up-to-date with 'origin/develop'.
      Already up-to-date.
      Deleted branch feature/cs (was bd890d0).
      
      Summary of actions:
      - The feature branch 'feature/cs' was merged into 'develop'
      - Feature branch 'feature/cs' has been removed
      - You are now on branch 'develop'
      
      1. git flow feature start <name>
        建立当前任务的 feature,如 git flow feature start cs,即建立一个分支名为 feature/cs,并切到该分支

        • 具体操作:
          • git checkout -b feature/<name> develop
            基于 develop 分支生成新分支 feature/<name>,并切到该分支
      2. 在 feature 分支进行开发,如需调试,可 push 到远端

      3. git flow feature finish <name>
        结束 feature 分支,并 merge 至 develop
        具体操作:

        • 检查当前 feature 和 develop 分支是否有冲突,有则提示解决冲突,没有则继续以下流程
        • git checkout develop
          切换到 develop 分支
        • git merge --no-ff feature/<name>
          merge feature/<name> 分支,并保留该分支 git 记录
        • git branch -d feature/<name>
          删除本地 feature 分支
          注:如果该分支已经上传到远端,则不影响远端分支
      4. git push
        上传 develop 分支

    3. 测试流程
      在一个版本结束提交 QA 测试时进行该流程。
      该流程由将项目管理者操作,个人开发者无需操作

      > git flow release start 1.6
      Switched to a new branch 'release/1.6'
      
      Summary of actions:
      - A new branch 'release/1.6' was created, based on 'develop'
      - You are now on branch 'release/1.6'
      
      Follow-up actions:
      - Bump the version number now!
      - Start committing last-minute fixes in preparing your release
      - When done, run:
      
       git flow release finish '1.6'
      
      > git flow release finish 1.6
      Switched to branch 'master'
      Your branch is up-to-date with 'origin/master'.
      Merge made by the 'recursive' strategy.
       c | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      Switched to branch 'develop'
      Your branch is up-to-date with 'origin/develop'.
      Merge made by the 'recursive' strategy.
       c | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      Deleted branch release/1.6 (was d829ec5).
      
      Summary of actions:
      - Latest objects have been fetched from 'origin'
      - Release branch has been merged into 'master'
      - The release was tagged 'v1.6'
      - Release branch has been back-merged into 'develop'
      - Release branch 'release/1.6' has been deleted
      
      1. git flow release start <name>
        建立当前版本的 release,如 git flow release start 1.1.2
        具体操作:
        • 检查是否已经有 release 分支,有则提示先结束 release 分支,没有则继续以下流程
        • git checkout -b release/<name> develop
          基于 develop 分支生成新分支 release/<name>,并切到该分支
      2. 选做,增加版本号
        • ./bump-version.sh 1.1.2
        • git commit -a -m "Bumped version number to 1.1.2"
      3. 选做,将 release 分支上传至远端,建议执行
        • git push
      4. QA 同学进行测试。如果测试时需要进行 bugfix,则在 release 分支上进行修改(此时必须执行3)
      5. git flow release finish <name>
        完成 release 测试,自动将代码 merge 到 master 和 develop 分支
        • git checkout master
          切换至 master 分支
        • git merge --no-ff release/<name>
          将 release 分支 merge 到 master 分支
        • git tag -a 1.2.2
          打 tag
        • git checkout develop
          切换至 develop 分支
        • git merge --no-ff release/<name>
          将 release 分支 merge 到 develop 分支
        • git branch -d release
          删除本地 release 分支
      6. git checkout master
        git push
        上传 master 分支
      7. git checkout develop
        git push
        上传 develop 分支
    4. hotfix 流程

      > git flow hotfix start 1.9
      Switched to a new branch 'hotfix/1.9'
      
      Summary of actions:
      - A new branch 'hotfix/1.9' was created, based on 'master'
      - You are now on branch 'hotfix/1.9'
      
      Follow-up actions:
      - Bump the version number now!
      - Start committing your hot fixes
      - When done, run:
      
       git flow hotfix finish '1.9'
      
      > git flow hotfix finish 1.9
      Switched to branch 'master'
      Your branch is up-to-date with 'origin/master'.
      Merge made by the 'recursive' strategy.
       c | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      Switched to branch 'develop'
      Your branch is up-to-date with 'origin/develop'.
      Merge made by the 'recursive' strategy.
       c | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      Deleted branch hotfix/1.9 (was 83e4746).
      
      Summary of actions:
      - Latest objects have been fetched from 'origin'
      - Hotfix branch has been merged into 'master'
      - The hotfix was tagged 'v1.9'
      - Hotfix branch has been back-merged into 'develop'
      - Hotfix branch 'hotfix/1.9' has been deleted
      
      1. git flow hotfix start <name>
        基于 master 分支 新建分支 hotfix/<name>
      2. 在该分支上进行 hotfix
      3. git flow hotfix finish <name>
        结束 hotfix 分支,并 merge 到 master 分支和 develop 分支
        具体操作:
        • git checkout master
        • git merge --no-ff hotfix/<name>
        • git checkout develop
        • git merge --no-ff hotfix/<name>
      4. git checkout master
        git push
        上传 master 分支的修改
      5. git checkout develop
        git push
        上传 develop 分支的修改

    相关文章

      网友评论

        本文标题:gitflow 工具使用

        本文链接:https://www.haomeiwen.com/subject/zifihxtx.html