<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Git 提交, 一起看看大廠的規(guī)范!

          共 4355字,需瀏覽 9分鐘

           ·

          2021-09-30 07:45

          點(diǎn)擊上方 Java學(xué)習(xí)之道,選擇 設(shè)為星標(biāo)

          每天18:30點(diǎn),干貨準(zhǔn)時(shí)奉上!

          來源: juejin.cn/post/6844903871832145927

          git是現(xiàn)在市面上最流行的版本控制工具,書寫良好的commit message能大大提高代碼維護(hù)的效率。但是在日常開發(fā)中由于缺少對(duì)于commit message的約束,導(dǎo)致填寫內(nèi)容隨意、質(zhì)量參差不齊,可讀性低亦難以維護(hù)。在項(xiàng)目中引入commit message規(guī)范已是迫在眉睫。

          Part1用什么規(guī)范?

          現(xiàn)在市面上比較流行的方案是約定式提交規(guī)范Conventional Commits),它受到了Angular提交準(zhǔn)則的啟發(fā),并在很大程度上以其為依據(jù)。約定式提交規(guī)范是一種基于提交消息的輕量級(jí)約定。它提供了一組用于創(chuàng)建清晰的提交歷史的簡單規(guī)則;這使得編寫基于規(guī)范的自動(dòng)化工具變得更容易。這個(gè)約定與SemVer相吻合,在提交信息中描述新特性、bug 修復(fù)和破壞性變更。它的 message 格式如下:

          <類型>[可選的作用域]: <描述>

          [可選的正文]

          [可選的腳注]

          Part2Quick Start

          1. 全局安裝commitizen & cz-conventional-changelog

          commitizen是一個(gè)撰寫合格commit message的工具,用于代替 git commit 指令,而cz-conventional-changelog適配器提供conventional-changelog標(biāo)準(zhǔn)(約定式提交標(biāo)準(zhǔn))。基于不同需求,也可以使用不同適配器。

          npm install -g commitizen cz-conventional-changelog
          echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

          安裝完畢后,可直接使用git cz來取代git commit

          全局模式下,需要 ~/.czrc 配置文件, 為commitizen指定Adapter

          2. 項(xiàng)目內(nèi)安裝commitlint & husky

          commitlint負(fù)責(zé)用于對(duì)commit message進(jìn)行格式校驗(yàn),husky負(fù)責(zé)提供更易用的git hook

          Use npm

          npm i -D husky @commitlint/config-conventional @commitlint/cli

          Use yarn

          yarn add husky @commitlint/config-conventional @commitlint/cli -D

          commitlint只能做格式規(guī)范,無法觸及內(nèi)容。對(duì)于內(nèi)容質(zhì)量的把控只能靠我們自己。

          3. 添加相應(yīng)配置

          創(chuàng)建commitlint.config.js

          # In the same path as package.json

          echo 'module.exports = {extends: ["@commitlint/config-conventional"]};' > ./commitlint.config.js

          引入husky

          # package.json

          ...,
          "husky": {
              "hooks": {
                "commit-msg""commitlint -e $GIT_PARAMS"
              }
          }

          4. 使用

          執(zhí)行 git cz 進(jìn)入 interactive 模式,根據(jù)提示依次填寫

          1.Select the type of change that you're committing 選擇改動(dòng)類型 (<type>)

          2.What is the scope of this change (e.g. component or file name)? 填寫改動(dòng)范圍 (<scope>)

          3.Write a short, imperative tense description of the change: 寫一個(gè)精簡的描述 (<subject>)

          4.Provide a longer description of the change: (press enter to skip) 對(duì)于改動(dòng)寫一段長描述 (<body>)

          5.Are there any breaking changes? (y/n) 是破壞性修改嗎?默認(rèn)n (<footer>)

          6.Does this change affect any openreve issues? (y/n) 改動(dòng)修復(fù)了哪個(gè)問題?默認(rèn)n (<footer>)

          生成的commit message格式如下:

          <type>(<scope>): <subject>
          <BLANK LINE>
          <body>
          <BLANK LINE>
          <footer>

          填寫完畢后,husky會(huì)調(diào)用commitlint對(duì)message進(jìn)行格式校驗(yàn),默認(rèn)規(guī)定typesubject為必填項(xiàng)。

          任何git commit指令的option都能用在 git cz指令上, 例如git cz -a

          Part3Commit message規(guī)范在rrd-fe落地使用情況

          針對(duì)團(tuán)隊(duì)目前使用的情況,我們討論后擬定了 commit message 每一部分的填寫規(guī)則。

          1. type

          type為必填項(xiàng),用于指定commit的類型,約定了featfix兩個(gè)主要type,以及docs、style、build、refactor、revert五個(gè)特殊type其余type暫不使用。

          # 主要type
          feat:     增加新功能
          fix:      修復(fù)bug

          # 特殊type
          docs:     只改動(dòng)了文檔相關(guān)的內(nèi)容
          style:    不影響代碼含義的改動(dòng),例如去掉空格、改變縮進(jìn)、增刪分號(hào)
          build:    構(gòu)造工具的或者外部依賴的改動(dòng),例如webpack,npm
          refactor: 代碼重構(gòu)時(shí)使用
          revert:   執(zhí)行g(shù)it revert打印的message

          # 暫不使用type
          test:     添加測(cè)試或者修改現(xiàn)有測(cè)試
          perf:     提高性能的改動(dòng)
          ci:       與CI(持續(xù)集成服務(wù))有關(guān)的改動(dòng)
          chore:    不修改src或者test的其余修改,例如構(gòu)建過程或輔助工具的變動(dòng)

          當(dāng)一次改動(dòng)包括主要type特殊type時(shí),統(tǒng)一采用主要type

          2. scope

          scope也為必填項(xiàng),用于描述改動(dòng)的范圍,格式為項(xiàng)目名/模塊名,例如:node-pc/common rrd-h5/activity,而we-sdk不需指定模塊名。如果一次commit修改多個(gè)模塊,建議拆分成多次commit,以便更好追蹤和維護(hù)。

          3. body

          body填寫詳細(xì)描述,主要描述改動(dòng)之前的情況修改動(dòng)機(jī),對(duì)于小的修改不作要求,但是重大需求、更新等必須添加body來作說明。

          4. break changes

          break changes指明是否產(chǎn)生了破壞性修改,涉及break changes的改動(dòng)必須指明該項(xiàng),類似版本升級(jí)、接口參數(shù)減少、接口刪除、遷移等。

          5. affect issues

          affect issues指明是否影響了某個(gè)問題。例如我們使用jira時(shí),我們?cè)?code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;color: rgb(30, 107, 184);background-color: rgba(27, 31, 35, 0.05);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;">commit message中可以填寫其影響的JIRA_ID,若要開啟該功能需要先打通jiragitlab。參考文檔:https://docs.gitlab.com/ee/integration/jira/index.html

          填寫方式例如:

          re #JIRA_ID
          fix #JIRA_ID

          Part4示例

          • 完整的commit message示例
          • 相應(yīng)的git log
          -- END --

           | 更多精彩文章 -



          加我微信,交個(gè)朋友
          長按/掃碼添加↑↑↑

          瀏覽 44
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  壁特壁最新视频 | 黄片无码在线观看 | 国产五月天婷婷 | 毛片黄色电影 | 精品免费在线 |