menu Chancel's blog
rss_feed
Chancel's blog
我就是这样的人

愉快地使用Git系列02 - 分支

作者:Chancel, 更新:2022 Dec 14, 字数:3735, 已阅:757

这篇是我读过非常好关于Git的介绍,对程序员来说,应该是通用大于方便

所以提交消息/分支创建应该有一套明显硬朗的逻辑,否则你可能经常不知道这个提交是干了什么事情

对于多人协作的分支管理,我想可以借鉴参考下这个规范

官方推荐的git工作方式

提交消息

在每一次提交时都需要注释这次提交的内容(不允许留白),注释规范参考以下标准

- [MUD] for Odoo涉及模块结构改变时,
    - 方法:[MUD] 模块名称 改变说明
    - 例如:tyerp_data 下 tyerp.paper 增加字段 x_length GIT 提交说明
    [MUD] tyerp_data tyerp.paper 增加字段 x_length
- [IMP] for improvements(改进)
- [FIX] for bug fixes(修改bug)
- [REF] for refactoring(代码重构)
- [ADD] for adding new resources(添加新资源)
- [REM] for removing of resources(删除资源)
- [MOV] for moving files (Do not change content of moved file, otherwise Git will loose track, and the history will be lost !), or simply moving code from a file to another one.移动文件(请不要在移动文件的时候更改文件内容,否则git将丢失对文件内容的跟踪,这样一来也会丢失文件内容的历史记录),或者移动代码
- [MERGE] for merge commits (only for forward/back-port)(合并修改)

Then, in the message itself, specify the part of the code impacted by your changes (module name, lib, transversal object, …) and a description of the changes.

- Always include a meaningful commit message: it should be self explanatory (long enough) including the name of the module that has been changed and the reason behind the change. Do not use single words like “bugfix” or “improvements”.
- Avoid commits which simultaneously impact multiple modules. Try to split into different commits where impacted modules are different (It will be helpful if we need to revert a module separately).

分支工作流程

主分支

  1. master 为主分支,这个分支的每个节点都表示可以发布为正式产品。
  2. develop 为开发分支,他的最新状态表示当前的开发状态。 系统的持续集成会从此分支抓取,并进行自动测试。
  3. 当develop 分支稳定到一定程度,将合并到开发主分支。

支持分支

支持分支用于团队进行功能开发、bug修复等操作,这些分支有生命周期,完成后要删除 这些分支分为3种情况:

  1. 功能(Feature)分支,用于新功能开发。
  2. 发布(Release)分支,用于发布前的准备,小bug修改。
  3. 修复(HotFix)分支

功能分支

  1. 从develop分支产生,并且最后合并到develop分支。
  2. 只存在于开发者本地库,不能推送到服务器。
  3. 命名方式:除了master, develop, release-, or hotfix-

分支产生

$ git checkout -b myfeature develop
Switched to a new branch “myfeature”
分支完成
$ git checkout develop
Switched to branch ‘develop’
$ git merge —no-ff myfeature
Updating ea1b82a..05e9557
(Summary of changes)
$ git branch -d myfeature
Deleted branch myfeature (was 05e9557).
$ git push origin develop

发布分支

  1. 从develop分支产生。
  2. 必须合并到develop和master。
  3. 命名方式:release
  4. 分支产生
$ git checkout -b release-1.2 develop
Switched to a new branch “release-1.2”
$ git commit -a -m “Bumped version number to 1.2”
[release-1.2 74d9424] Bumped version number to 1.2
1 files changed, 1 insertions(+), 1 deletions(-)
分支完成
$ git checkout master
Switched to branch ‘master’
$ git merge —no-ff release-1.2
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2

同时合并到develop分支

$ git checkout develop
Switched to branch ‘develop’
$ git merge —no-ff release-1.2
Merge made by recursive.
(Summary of changes)

修复分支

  1. 从master分支产生。
  2. 必须合并到develop和master。
  3. 命名方式:hotfix
// 分支的产生
$ git checkout -b hotfix-1.2.1 master
Switched to a new branch “hotfix-1.2.1”
...
$ git commit -a -m “Bumped version number to 1.2.1”
[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)
$ git commit -m “Fixed severe production problem”
[hotfix-1.2.1 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)
// 分支的完成
$ git checkout master
Switched to branch ‘master’
$ git merge —no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2.1
// 分支的切换
$ git checkout develop
Switched to branch ‘develop’
$ git merge —no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]
目录