

Git Commit Message 规范与模板 | cf020031308.github.io
source link: https://cf020031308.github.io/wiki/git-commit-message?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Git Commit Message 规范与模板
业界标准:AngularJS
来自 AngularJS 所用的规范,格式如下:
<type>(<scope>): <subject>
<body>
<footer>
各段内容说明:
- type: feat/fix/docs/refactor/perf/test/style/revert/chore
- scope: 影响范围(组件或文件),可省略
- subject: 第一人称现在时,动词开头,小写开头,英语 50 字符以内,结尾无句号
- body: 第一人称现在时,说明动机,与之前的对比,英语每行 72 字符以内
- footer: 与前不兼容的改动用 'BREAKING CHANGE:' 开头,给出修复方案。对 Issues 进行操作
自动生成 ChangeLog
标准化的 Git Commit Message 可以用工具过滤出 feat 和 fix 的 Commit 生成 ChangeLog,例如:
git log --format='%s (%h)' --reverse --grep '^\(feat\|fix\)' --since=2020-01-01 --before=2020-02-01 | sed 's/([^)]*):/:/' | sort -k1,1 -s
可以添加到 ~/.gitconfig
里:
[alias]
change-of-last-month = !sh -c 'git log --format=\"%s (%h)\" --reverse --grep \"^\\(docs\\|feat\\|fix\\|perf\\|refactor\\|test\\)\" --since=`date -v-1m +\"%Y-%m-01\"` --before=`date +\"%Y-%m-01\"` | sed \"s/([^)]*):/:/\" | sort -k1,1 -s'
之后用 git change-of-last-month
就可以输出上个月的 ChangeLog。
1. 自定义一个模板
比如这是我的模板,权作 Commit 时的提醒:
># feat/fix/docs/refactor/perf/test/style/revert/chore(scope/issue): changelog
# Modify issues if necessary
# Details if any
#
开头的行会被作为注释过滤掉。
2. 加入到 git 配置中
git config --global commit.template path/to/template
也可以在 ~/.gitconfig
中手动添加
[commit]
template = path/to/template
3. 提交时使用模板
之后提交时,使用 git commit
不带 -m
参数,就可以调出模板。
Recommend
-
15
-
24
寿司与神的故事 没有人知道谢尔美食广场里经营着多少家专卖美食的商户,但每个人都知道这里有一家营业多年的寿司店,其出产的寿司之美味驰名整个乌图邦,店长更是因此被尊称为“寿司之神”。 寿司之神老态龙钟,周身皱纹如同干...
-
53
【编者的话】Git是现在市面上最流行的版本控制工具,书写良好的commit message能大大提高代码维护的效率。但是在日常开发中由于缺少对于commit message的约束,导致填写内容随意、质量参差不齐,可读性低亦难以维护。在项目中引入commit m...
-
32
Github Pages 背后的 Jekyll 在代码仓库 settings 中开通 Github Pages...
-
7
My Worst Git Commit Message Ever Dec 23, 2016 I was in the car with my wife talking to her as I worked and this was the message: git commit -m "misc: → '''''''''''''''''''vvvvvvvvvvv...
-
14
How to capture a git commit message and execute an action advertisements I'm new to git and I want to be able to capture the commit message af...
-
5
规范你的Git Commit message – 简书 规范你的Git Commit message2019.06.10 22:51:49字数 302阅读 5写在前面关于Git,大家想必都很熟悉,因为我们几乎每天都在重复着git add、git commit、git push等命令,自然也就留下很多“痕迹”,如果没有好...
-
7
Git Hook to Add Issue Number to Commit Message Posted on 2019, Jun 16 3 mins read When using project management system (...
-
7
Git: 如何写好 Commit Message 发表于 2017-11-15 分类于 Git Valine: 0 本文字数: 1.9k 阅读时长 ≈ 2 分...
-
5
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK