发布于 

how to write commit message

how to write commit message

Commit格式

包含三部分:Header(必填)、body(选填)、footer(选填)

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

type(必填)

  1. type说明commit的类型,可以分为2大类: Development 和 Production
    • Development:这类修改一般是项目管理类的变更,不会影响最终用户和生产环境的代码,比如 CI 流程、构建方式等的修改。遇到这类修改,通常也意味着可以免测发布。
    • Production:这类修改会影响最终的用户和生产环境的代码。所以对于这种改动,我们一定要慎重,并在提交前做好充分的测试。
  2. type具体类型
类型 类别 说明
feat Production 新增功能
fix Production Bug修复
perf Production 提高代码性能的变更
style Development 代码格式化,比如代码格式化,删除空行等
refactor Production 其他代码类的更变,不属于前面4中,例如简化代码、重命名变量、删除冗余代码等
test Development 新增测试用例或是更新现有测试用例
ci Development 持续集成和部署相关的改动,比如修改jenkins、gitlab ci等
docs Development 文档类的更新
chore Development 其他类型,比如:构建流程、依赖管理或者辅助工具的变更
  1. image-20211014101943888

scope(选填)

  1. scope:是用来说明commit的影响范围,必须是名词的。不同项目会有不同的scope。比如模块的名字

subject(必填)

  1. subject:是commit的简短描述

Body

commit中header做了高度概括,body是可选的部分,对commit做详细的描述

Footer不是必选的。说明本次commit的后果

合并提交(git rebase -i)

## add 修改的文件
git add .
## 图形化编写commit的信息
git cz
## commit记录合并
git rebase -i <commitId>
## 查看commit的header记录
git log --oneline
## 查看commit详情
git log -p -6
## git rebase -i
git rebase -i <commitId>
pick d60d3dd iterm commit55
pick fd11a17 fix(21312): 321321

# Rebase 3dbcad1..fd11a17 onto 3dbcad1 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.

修改Commit Message

  1. git commit –amend:修改最近一次 commit 的 message;
  2. git rebase -i:修改某次 commit 的 message。

Commit Message规范自动化

  1. 参考实现:自动化提交规范