{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/git-workflow-commit-convention/",
  "atlas": "https://www.pystone.net/?node=git-workflow-commit-convention#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/git-workflow-commit-convention.md",
  "context": "https://www.pystone.net/notes/git-workflow-commit-convention.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:git-workflow-commit-convention",
  "slug": "git-workflow-commit-convention",
  "title": "【SCM】Git workflow & commit message convention",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【SCM】Git workflow & commit message convention",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "80eafb37a1d5371e58ba2cedb17bf7429a6fbd786a9dcb678ff37411bd62028c",
  "assets": [
    {
      "reference": "assets/0035 - 【SCM】Git workflow & commit message convention__resource-002-1924ebe1d8c4.png",
      "url": "/media/4b7b11e08b8f5235c1c3.png",
      "mediaType": "image/png",
      "contentHash": "4b7b11e08b8f5235c1c318e93da7a078fe04e17419066cd096055a346eb65256",
      "byteLength": 33319,
      "width": 1181,
      "height": 458
    },
    {
      "reference": "assets/0035 - 【SCM】Git workflow & commit message convention__resource-001-d83270218e0c.png",
      "url": "/media/12e02269feba5f020f4c.png",
      "mediaType": "image/png",
      "contentHash": "12e02269feba5f020f4cb40ef163946ff9688fef8ce875609c155fbbf9d234a6",
      "byteLength": 236306,
      "width": 1150,
      "height": 1524
    },
    {
      "reference": "assets/bd69e25f77610ca314f31f1e3353e9a.png",
      "url": "/media/f4ca40ddfa630873ced3.png",
      "mediaType": "image/png",
      "contentHash": "f4ca40ddfa630873ced33fe8eabe2ccfead832a12f25c2b1297b8699d132d147",
      "byteLength": 13576,
      "width": 559,
      "height": 221
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "【SCM】Git workflow & commit message convention",
      "anchor": "scmgit-workflow-commit-message-convention",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#scmgit-workflow-commit-message-convention"
    },
    {
      "depth": 2,
      "text": "Why",
      "anchor": "why",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#why"
    },
    {
      "depth": 2,
      "text": "Workflow",
      "anchor": "workflow",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#workflow"
    },
    {
      "depth": 3,
      "text": "GitHub flow",
      "anchor": "github-flow",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#github-flow"
    },
    {
      "depth": 3,
      "text": "git-flow",
      "anchor": "git-flow",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#git-flow"
    },
    {
      "depth": 3,
      "text": "Subversion Best Practices",
      "anchor": "subversion-best-practices",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#subversion-best-practices"
    },
    {
      "depth": 2,
      "text": "commit message convention",
      "anchor": "commit-message-convention",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#commit-message-convention"
    },
    {
      "depth": 3,
      "text": "相关命令",
      "anchor": "相关命令",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4"
    },
    {
      "depth": 3,
      "text": "Convention 1: imperative mood",
      "anchor": "convention-1-imperative-mood",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#convention-1-imperative-mood"
    },
    {
      "depth": 3,
      "text": "Convention 2: Angular Git commit message guidelines",
      "anchor": "convention-2-angular-git-commit-message-guidelines",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#convention-2-angular-git-commit-message-guidelines"
    },
    {
      "depth": 4,
      "text": "Commit Message Header (mandatory)",
      "anchor": "commit-message-header-mandatory",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#commit-message-header-mandatory"
    },
    {
      "depth": 4,
      "text": "Commit Message Body and Footer",
      "anchor": "commit-message-body-and-footer",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#commit-message-body-and-footer"
    },
    {
      "depth": 4,
      "text": "Revert commits",
      "anchor": "revert-commits",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#revert-commits"
    },
    {
      "depth": 2,
      "text": "Hooks",
      "anchor": "hooks",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#hooks"
    },
    {
      "depth": 3,
      "text": "Git Hooks",
      "anchor": "git-hooks",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#git-hooks"
    },
    {
      "depth": 4,
      "text": "本地使用",
      "anchor": "本地使用",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#%E6%9C%AC%E5%9C%B0%E4%BD%BF%E7%94%A8"
    },
    {
      "depth": 4,
      "text": "与团队共享的方案",
      "anchor": "与团队共享的方案",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#%E4%B8%8E%E5%9B%A2%E9%98%9F%E5%85%B1%E4%BA%AB%E7%9A%84%E6%96%B9%E6%A1%88"
    },
    {
      "depth": 4,
      "text": "应用",
      "anchor": "应用",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#%E5%BA%94%E7%94%A8"
    },
    {
      "depth": 5,
      "text": "Commit Message",
      "anchor": "commit-message",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#commit-message"
    },
    {
      "depth": 5,
      "text": "进阶——email",
      "anchor": "进阶email",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#%E8%BF%9B%E9%98%B6email"
    },
    {
      "depth": 3,
      "text": "SVN Hooks",
      "anchor": "svn-hooks",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#svn-hooks"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/git-workflow-commit-convention/#ref"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:software-engineering-and-quality",
      "title": "软件工程与质量保障",
      "url": "https://www.pystone.net/notes/software-engineering-and-quality/",
      "atlas": "https://www.pystone.net/?node=software-engineering-and-quality#knowledge-atlas",
      "label": "软件工程与质量保障",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "CI-CD与质量保障/CI-CD工具链中的“【SCM】Git workflow & commit message convention”导航项",
      "citation": "https://www.pystone.net/notes/software-engineering-and-quality/#ci-cd%E4%B8%8E%E8%B4%A8%E9%87%8F%E4%BF%9D%E9%9A%9Cci-cd%E5%B7%A5%E5%85%B7%E9%93%BE"
    }
  ],
  "contentMarkdown": "# 【SCM】Git workflow & commit message convention\n\n﻿# 【SCM】Git workflow & commit message convention\n\n> 创建时间：2021/7/20 15:36\n\n* Why\n  * Workflow\n    * GitHub flow\n    * git-flow\n    * Subversion Best Practices\n  * commit message convention\n    * 相关命令\n    * Convention 1: imperative mood\n    * Convention 2: Angular Git commit message guidelines\n      * Commit Message Header (mandatory)\n      * Commit Message Body and Footer\n      * Revert commits\n  * Hooks\n    * Git Hooks\n      * 本地使用\n      * 与团队共享的方案\n      * 应用\n        * Commit Message\n        * 进阶——email\n    * SVN Hooks\n  * Ref\n\n## Why\n\n流程上的规范，对于小体量的事情，对于小公司、独立开发者来讲，必要性没有那么大，收益不容易体现出来，甚至有点冗余。但是当公司变大后，做的事情复杂度提高之后，流程规范的收益就会体现出来，能提高沟通效率，节约时间，降低风险。\n\n## Workflow\n\nGitHub flow - If your team is doing **continuous delivery** of software, I would suggest to adopt a much simpler workflow GitHub flow.\n\ngit-flow - If, however, you are building software that is explicitly **versioned** , or if you need to **support multiple versions** of your software in the wild, then git-flow may still be as good of a fit to your team.\n\n**To conclude, always remember that panaceas don't exist. Consider your own context.**\n\n### GitHub flow\n\nhttps://guides.github.com/introduction/flow/\n\n![](assets/0035 - 【SCM】Git workflow & commit message convention__resource-002-1924ebe1d8c4.png)\n\n  * There's only one rule: **anything in the main branch is always deployable**.\n\n  * Commit messages are important.\n\n  * Pull Requests help start code review and conversation about proposed changes before they're merged into the main branch.\n\n  * you can deploy from a branch for final testing in production before merging to main.\n\n需要的工作：\n\n  * 部署作业完全自动化\n  * 测试自动化（编写测试代码，维护测试代码）\n\n### git-flow\n\nhttps://nvie.com/posts/a-successful-git-branching-model/\n\n![](assets/0035 - 【SCM】Git workflow & commit message convention__resource-001-d83270218e0c.png)\n\n分支| 用途\n---|---\nmaster| 稳定版本\ndevelop| 最新版本\nrelease| 发布新版本\nhotfix| 修复线上Bug\nfeature| 实现新特性\n\n开发过程：\n在 **master** 分支上创建 **develop** 分支\n开发人员在 develop 分支上实现新功能，包括:新特性与 Bug 修复\n若存在多个新特性可以并行开发，则开发主管可创建一个或多个 **feature** 分支(特性分支)，命名规范:feature-分支创建日期-新特性关键字，例如:feature-20190919-i18n\n当新特性开发完毕后，开发主管需将 feature 分支合并到 develop 分支，最后需删除 feature 分支\n\n准备发布新版本\n\n确认 develop 分支上的功能是否开发完毕\n若开发完毕，则创建 release 分支(发布分支)，命名规则:release-分支创建日期-待发布版本号，例\n如:release-20190919-v1.0.0\n开发人员在 release 分支上修复测试人员提交给自己的 Bug\n只允许在 release 分支上修复 Bug，不允许提交任何新特性\n\n安排测试人员，对 release 分支进行集成测试，测试完毕后\n将 release 分支同时合并到 master 分支与 develop 分支\n对 master 分支进行冒烟测试后\n修改 master 分支上的 Maven 快照版为发布版(去掉 SNAPSHOT 后缀)\n添加发布日志(RELEASE.md)\n在 master 分支上创建标签，命名规则:tag-日期-版本，例如:tag-20190919-v1.0.0\n删除 release 分支\n通知测试主管新版本已发布完毕\n\n修复线上 Bug\n\n创建 hotfix 分支\n\n从 master 分支某个 tag 上创建一个 hotfix 分支(热修复分支)，命名规则:hotfix-分支创建日期-待\n发布版本号，例如:hotfix-20190919-v1.0.1\n修复测试后\n将 hotfix 分支同时合并到 master 与 develop 分支\n修改 master 分支上的 Maven 快照版为发布版(去掉 SNAPSHOT 后缀)\n添加发布日志(RELEASE.md)\n在 master 分支上创建标签\n\n其他资料：https://www.cnblogs.com/sloong/p/5868292.html\n\n### Subversion Best Practices\n\nhttps://svn.apache.org/repos/asf/subversion/trunk/doc/user/svn-best-practices.html\n\n  * The Never-Branch system\n  * The Always-Branch system\n  * The Branch-When-Needed system\n\nOther Guideline:https://nanopdf.com/download/subversion-workflow-guide-contents-joanne-carr-ltgt-january-2010_pdf\n\n```csharp\nstring str1 = String.Empty;\nstring str2 = String.Empty;\n\nstr2 = String.Intern(sb.ToString());\n\nif((object)str1==(object)str2)\n    Console.WriteLine(&quot;The strings are equal.&quot;);\nelse\n    Console.WriteLine(&quot;The strings are not equal.&quot;);\n\n```\n\n## commit message convention\n\nA diff will tell you what changed, but only the commit message can properly tell you why.\n\n### 相关命令\n\n```csharp\nstring str1 = String.Empty;\nstring str2 = String.Empty;\n\nstr2 = String.Intern(sb.ToString());\n\nif((object)str1==(object)str2)\n    Console.WriteLine(&quot;The strings are equal.&quot;);\nelse\n    Console.WriteLine(&quot;The strings are not equal.&quot;);\n\n```\n\n### Convention 1: imperative mood\n\nhttps://chris.beams.io/posts/git-commit/\n\n> 一些思路可以借鉴。\n\n  1. Separate subject from body with a blank line\n\n```csharp\nstring str1 = String.Empty;\nstring str2 = String.Empty;\n\nstr2 = String.Intern(sb.ToString());\n\nif((object)str1==(object)str2)\n    Console.WriteLine(&quot;The strings are equal.&quot;);\nelse\n    Console.WriteLine(&quot;The strings are not equal.&quot;);\n\n```\n  2. Limit the subject line to 50 characters\n  3. Begin all subject lines with a capital letter\n  4. Do not end the subject line with a period\n  5. Use the imperative mood in the subject line\n  6. Wrap the body at 72 characters\n  7. Use the body to explain what and why\n\nCode is generally self-explanatory. There is no need to explain how in most cases.\n\n> Refactor subsystem X for readability\n>  Update getting started documentation\n>  Remove deprecated methods\n>  Release version 1.0.0\n>  Fix bug with Y\n>  Change behavior of X\n>  含义：If applied, this commit will Fixed bug with Y\n\n### Convention 2: Angular Git commit message guidelines\n\nhttps://www.conventionalcommits.org/en/v1.0.0/\nhttps://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-header\n\n#### Commit Message Header (mandatory)\n\n```csharp\nstring str1 = String.Empty;\nstring str2 = String.Empty;\n\nstr2 = String.Intern(sb.ToString());\n\nif((object)str1==(object)str2)\n    Console.WriteLine(&quot;The strings are equal.&quot;);\nelse\n    Console.WriteLine(&quot;The strings are not equal.&quot;);\n\n```\n\nThe <type> and <summary> fields are mandatory, the (<scope>) field is optional.\n\n* * *\n\nType:\n**build** : Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)\n**ci** : Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)\n**docs** : Documentation only changes\n**feat** : A new feature\n**fix** : A bug fix\n**perf** : A code change that improves performance\n**refactor** : A code change that neither fixes a bug nor adds a feature\n**test** : Adding missing tests or correcting existing tests\n**chore** : A code change that external user won't see (eg: change to .gitignore file or .prettierrc file)\n**style** : A code that is related to styling\n\n* * *\n\nScope - The scope should be the name of the npm package affected\n\n* * *\n\nSummary\n\n  * use the imperative, present tense: \"change\" not \"changed\" nor \"changes\"\n  * don't capitalize the first letter\n  * no dot (.) at the end\n\n#### Commit Message Body and Footer\n\nBody: Explain the motivation for the change in the commit message body.\n\nFooter: The footer can contain information about breaking changes and is also the place to reference GitHub issues, Jira tickets, and other PRs that this commit closes or is related to.\n\n#### Revert commits\n\nIf the commit reverts a previous commit, it should begin with `revert:` , followed by the header of the reverted commit.\n\n## Hooks\n\nHook 就是在执行某个事件之前或之后进行一些其他额外的操作\n\n### Git Hooks\n\n一些常用的触发点：\n\napplypatch-msg\npre-applypatch\npost-applypatch\npre-commit\nprepare-commit-msg\ncommit-msg\npost-commit\npre-rebase\npost-checkout\npost-merge\npre-receive\nupdate\npost-receive\npost-update\npre-auto-gc\npost-rewrite\npre-push\n\n#### 本地使用\n\n查阅文档：\nhttps://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks\nhttps://segmentfault.com/a/1190000022970270\nhttps://githooks.com/\n\n#### 与团队共享的方案\n\n.git文件夹不会git跟踪，要创建一个.githooks存储hook脚本\ngit 版本为2.9或以上：\n\n```cpp\nstring s = String.Empty;\n\n```\n\n#### 应用\n\n##### Commit Message\n\nhttps://www.datree.io/resources/git-commit-message\n\n用法：替换掉 .githooks/commit-msg文件即可。该文件的内容只要是脚本语言就可以（shell,python,perl等）\n\n```cpp\nstring s = String.Empty;\n\n```\n\n##### 进阶——email\n\nhttps://www.jianshu.com/p/f049cd1c44bc\n\n### SVN Hooks\n\n可以在Server端Hook，实现Commit Message规范、Code Review、CICD等功能。\nhttps://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-repository-hooks.html\nhttps://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.create.hooks\n\n![](assets/bd69e25f77610ca314f31f1e3353e9a.png)\n\n## Ref\n\nhttps://nvie.com/posts/a-successful-git-branching-model/\nhttps://svn.apache.org/repos/asf/subversion/trunk/doc/user/svn-best-practices.html\nhttps://chris.beams.io/posts/git-commit/\n"
}
