Git Commit Message 规范与模板

2020-03-12 21:27:15 +08:00
 cf020031308

业界标准:AngularJS

来自 AngularJS 所用的规范,格式如下:

<type>(<scope>): <subject>

<body>

<footer>

各段内容说明:

自动生成 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 参数,就可以调出模板。

6593 次点击
所在节点    git
19 条回复
loading
2020-03-12 21:29:57 +08:00
我最近也在使用这个。

如果各位实在不知道如何写,可以直接抄一个这个:
whatthecommit.com
hantsy
2020-03-12 22:01:33 +08:00
Good job
labulaka521
2020-03-12 22:09:05 +08:00
收藏了
hallDrawnel
2020-03-12 22:31:11 +08:00
我们组就在用这个
xiqingongzi
2020-03-12 22:43:24 +08:00
gitstyle.js.orf
xiqingongzi
2020-03-12 22:43:31 +08:00
Smash
2020-03-12 23:06:07 +08:00
Google 的规范 Github 上应用得挺广泛的
sunwei0325
2020-03-12 23:33:38 +08:00
生成 changelog 的不错, 现在用的是一个 npm 命令 conventional-changelog
noqwerty
2020-03-13 00:11:59 +08:00
用了一段时间 commitizen 了,挺香的,逼着自己写详细的 commit message
xiadada
2020-03-13 00:15:28 +08:00
@noqwerty 这个配置好恶心
noqwerty
2020-03-13 00:20:37 +08:00
@xiadada #10 很方便啊,如果用 Angular 规范的话按着文档来就三行命令的事,之后就 git cz 就可以了。

https://github.com/commitizen/cz-cli#conventional-commit-messages-as-a-global-utility
CBS
2020-03-13 01:22:52 +08:00
学习了。
geelaw
2020-03-13 03:13:11 +08:00
Imperative 是“祈使语气”,而不是“第一人称”,而且根据最先的原文这个只适用于对代码改变的描述(原因描述需要其他人称和语气)。
blueset
2020-03-13 07:01:08 +08:00
zhuzhibin
2020-03-13 09:06:51 +08:00
不是 git cz?
RoshanWu
2020-03-13 09:43:05 +08:00
自动生成 ChangeLog 如果不那么追求定制化,需要比较傻瓜的方式,可以用用我的这个:
https://github.com/roshanca/autochangelog

这里是生成的例子:
https://github.com/roshanca/autochangelog/blob/master/CHANGELOG.md
FaiChou
2020-03-13 10:45:11 +08:00
style 这种类型是对代码层面对优化 lint,还是指前端样式上的调整?
Poarry
2020-03-13 15:25:11 +08:00
收藏了
sepdy
2020-03-14 03:57:54 +08:00
我倒是觉得能表述的内容太少。gitmoji 用起来更好玩。看起来没那么“单调”

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/652309

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX