作者:Chancel, 更新:2022 Dec 14, 字数:3735, 已阅:757
这篇是我读过非常好关于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).
支持分支用于团队进行功能开发、bug修复等操作,这些分支有生命周期,完成后要删除 这些分支分为3种情况:
分支产生
$ 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
$ 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)
// 分支的产生
$ 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)