git工作流

2019-11-21  本文已影响0人  tommwq

分支

git工作流使用多个分支来完成版本管理工作。这些分支包括master分支、develop分支、feature分支、release分支和hotfix分支。

master分支

develop分支

develop分支维护正在开发中的代码。develop分支从master分支创建。当开发新功能时,开发者从develop分支创建feature分支进行开发。开发工作完成后,再合并到develop分支,之后删除对应的feature分支。在修复缺陷时,同样从develop分支创建fix分支,处理流程同feature分支一样。在发布过程中(建立release分支后),只有修复缺陷的feature分支和hotfix分支可以合并到develop分支。

feature分支

feature分支是为实现指定特性,或修复特定缺陷而建立的分支。feature分支从develop分支创建,在完成开发工作后,合并入develop分支,然删除该feature分支。feature分支应当命名为issue-XXX,其中XXX是特性对应的issue编号。

release分支

release分支负责维护即将发布的代码。release分支从develop分支创建,进行缺陷修复、生成文档和其他发布相关的任务。在发布过程中,如果有hotfix分支,或者修复缺陷的feature分支合并到develop分支,应当执行develop分支同release分支的合并。当发布完成后,将release分支合并到master分支,并分配一个版本号作为标签。然后删除该release分支。release分支应当以release-XXX命名,其中XXX是版本号。

hotfix分支

hotfix分支用于进行缺陷紧急修复。hotfix分支从master分支创建,修复完成后,合并入develop分支和master分支,并为master分支建立新标签。

提交信息

提交信息格式如下

<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>

其中,type可以是如下类型

| 类型 | 说明 |
| feat | 新特性 |
| fix | 修复 |
| docs | 文档 |
| style | 代码格式 |
| refactor | 重构 |
| test | 测试代码 |
| chore | 辅助工具 |

scope是影响的范围,比如数据层、控制层、视图层等,因项目而异。subject是提交的主题,其限制如下

  1. 使用英文编写。
  2. 不超过50字符。
  3. 首字母小写。
  4. 以动词开头,使用第一人称现在时。
  5. 结尾不加句号(.)。

body是对提交的详细描述,可以有多行。body的要求如下

  1. 使用英文编写。
  2. 不超过72字符。
  3. 使用第一人称现在时。
  4. 必须说明变更的目的和内容。

下面是一个body示例

More detailed explanatory text, if necessary. Wrap it to
about 72 characters or so.

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Use a hanging indent

footer是可选的部分,仅当提交不兼容变更和关闭issue时使用。提交不兼容变更时,footer当以BREAKING CHANGE开头,并描述变更影响,如

BREAKING CHANGE: isolate scope bindings definition has changed.

    To migrate the code follow the example below:

    Before:

    scope: {
      myAttr: 'attribute',
    }

    After:

    scope: {
      myAttr: '@',
    }

    The removed `inject` wasn't generaly usefull for directives so there should be no code using it.

在关闭issue时,foot要写明issue编号,如

Closes #1234

Closes #12, #34, #56

Revert

如果当前提交目的是撤销以往的提交,提交header必须以“reert:“开头,接着是被撤销的提交的header。body为”This reverts commit <hast>.“,其中hash是被撤销提交的散列码。示例如下

revert: feat(pencil): add 'graphiteWidth' option

This reverts commit 667ecc1654a317a13331b17617d973392f415f02.

参考资料:

  1. https://github.com/thoughtbot/dotfiles/blob/master/gitmessage
  2. https://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message
  3. http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
上一篇 下一篇

猜你喜欢

热点阅读