鍓嶇涔嬭矾锛氱敤 Angular 瑙勮寖鏉ョ害鏉熷洟闃?git 鎻愪氦
Posted 鎺橀噾寮€鍙戣€呯ぞ鍖?/a>
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍓嶇涔嬭矾锛氱敤 Angular 瑙勮寖鏉ョ害鏉熷洟闃?git 鎻愪氦相关的知识,希望对你有一定的参考价值。
鏈枃鍑鸿嚜銆屾帢閲戠ぞ鍖恒€嶏紝娆㈣繋鎴炽€岄槄璇诲師鏂囥€嶉摼鎺ュ拰浣滆€呰繘琛屾妧鏈氦娴?馃帀馃帀
CommitMsg
git 鎻愪氦瑙勮寖
鑳屾櫙
鍥㈤槦鍗忎綔寮€鍙戯紝 git
浣滀负涓€涓紑婧愮殑鍒嗗竷寮忕増鏈帶鍒剁郴缁燂紝淇ㄧ劧鎴愪负褰撲笅鏈€鍙楁鐨勯」鐩唬鐮佺増鏈鐞嗗伐鍏凤紝 鍗虫槸鍥㈤槦锛屽氨瑕佹湁涓€瀹氱殑瑙勭煩锛岃鑼冿紝杩欐牱鎵嶈兘鏇村ソ鐨勫彂鎸ュ洟闃熸晥鐜囥€傜啛鎮?git
鐨勫皬浼欎即閮界煡閬擄紝姣忔鎻愪氦浠g爜锛?閮借鍐?Commit message锛堟彁浜よ鏄庯級锛屽惁鍒欏氨涓嶅厑璁告彁浜わ紝鑷充簬鎻愪氦鐨勪俊鎭?git
骞舵病鏈夎繘琛岀害鏉燂紝浠ヨ嚦浜庯紝 鎻愪氦涓婃潵鐨勮鏄庢槸浜旇姳鍏棬锛岀敱姝ょぞ鍖哄嚭鐜颁簡澶氱鍐欐硶瑙勮寖锛屽叾涓?span class="mq-13"> Angular 瑙勮寖 鏄洰鍓嶆渶涓哄箍娉涚殑鍐欐硶锛屾瘮杈冨悎鐞嗗拰绯荤粺鍖栥€傛湰鏂囧氨鏉ヨ涓€璁蹭袱绉嶄娇鐢?Angular 瑙勮寖鐨勬柟娉曘€?/p>
娉曚竴锛屽熀浜庨」鐩€氳繃 hooks 瑙﹀彂锛堟垜鍙稿洟闃熺敤鐨勬鏂规硶锛?/h4>
杩欑鏂规硶鐨勫ソ澶勬槸锛屼换浣曚汉鍙鎯冲線鏈」鐩彁浜?commit锛屽氨蹇呴』鎸夌収瑙勮寖锛屽惁鍒欎笉鐒舵彁浜ゃ€?/p>
瀹夎鎵€闇€渚濊禆锛?nbsp;
npm i--save-dev husky chalk
锛?/span>鍦ㄩ」鐩殑鏍圭洰褰曟柊寤轰竴涓枃浠跺す
.github
锛堝悕瀛楅殢鎰忥級锛岃繖涓枃浠跺す涓撻棬鐢ㄦ潵瀛樻斁 github 鐩稿叧鐨勪笢瑗匡紱鍦ㄤ笂涓€姝ョ殑鏂囦欢澶逛腑鏂板缓
node
鑴氭湰鏂囦欢verifyCommitMsg
锛堝悕瀛楅殢鎰忥級锛?/span>鍦ㄤ笂涓€姝ョ殑鑴氭湰鏂囦欢涓啓鍏ヤ竴涓嬩唬鐮侊細
#!/bin/env node
const chalk = require('chalk');
const msgPath = process.env.HUSKY_GIT_PARAMS;
if (!msgPath) {
console.error(chalk.red(`process.env.HUSKY_GIT_PARAMS can't be ${msgPath},please check`));
process.exit(1);
}
console.log('HUSKY_GIT_PARAMS: ', msgPath);
const msg = require('fs')
.readFileSync(msgPath, 'utf-8')
.trim();
console.log(msg);
const commitRE = /^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/;
if (!commitRE.test(msg)) {
console.log();
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
chalk.red(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
) +
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
` ${chalk.green(`fix(v-model): handle events on blur (close ###28)`)}\n\n` +
chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`)
// chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
);
process.exit(1);
}
鍦?nbsp;package.json
澧炲姞/淇敼 hooks锛屽涓嬶細
...
"husky": {
"hooks": {
"commit-msg": "node .github/verifyCommitMsg"
}
},
...
杩欐牱灏卞仛鍒颁簡姣忔鎻愪氦閮戒細妫€鏌?commit 淇℃伅浜嗭紝褰撲笉绗﹀悎瑙勮寖鏃讹紝浼氱粰鍑烘彁绀恒€備緥濡傦細
娉曚簩锛屽熀浜?npm 渚濊禆鎻掍欢
杩欑鏂规硶鐨勫ソ澶勬槸锛屾彁浜ゆ瘮杈冧汉鎬у寲銆?/p>
鍏ㄥ眬瀹夎渚濊禆锛?nbsp;
npm i-g commitizen
鍒濆鍖栭€傞厤鍣紝
commitizen init cz-conventional-changelog--save-dev--save-exact
鐢?nbsp;
git cz
鍛戒护 浠f浛git commit
渚嬪锛?/p>
===馃馃 鏂囦腑涓嶈冻锛屾杩庢寚姝?馃お馃お===
以上是关于鍓嶇涔嬭矾锛氱敤 Angular 瑙勮寖鏉ョ害鏉熷洟闃?git 鎻愪氦的主要内容,如果未能解决你的问题,请参考以下文章