background
Learn how to use a recent specifications git
to develop more efficient, relatively easy to find a specification comment
tool, so wanted to record it. In general, commit message
it should be clear, explain the purpose of this submission. So it is necessary to standardize some of these comment
become readable, commitizen
it is a relatively easy to use tool recently discovered.
git
General submitted beginners will use git commit -m "hello world"
to submit comment
, but something like hello world
this does not make sense comment
people can not understand what in the end is the submission to, so we have to regulate what comment
is standardized.
PS:下面是一些基础介绍如果大佬请直接查看第二部分
1. commit message format (information field)
commit message generally divided into three portions Header, Body and Footer
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>
其中,Header 是必需的,Body 和 Footer 可以省略
Example:
PS D:\git\pythonPractice> git log
commit 58a7a966acb9aa2fffc0e02c9ce3be64b8949991 (HEAD -> master)
Author: Zhiwei Tian <[email protected]>
Date: Fri Aug 17 17:38:36 2018 +0800
feat(serve): add grpc server
1.1 HEAD
-
type
For explaining acommit
category, only allow use of the identification 7
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动
-
scope
Commit to influence the scope of this description, i.e., a brief description will be directed to the partially modified, such as the data layer, the control layer, the view layer and the like, -
subject
Location comment is located, a short description of this submission
1.2 Body is a detailed description of the commit time may be divided into a plurality of rows
1.3 Footer section is only used in two cases
- Incompatible changes
If the current code is not compatible with the previous version, the
Footer
part toBREAKING CHANGE
begin with, followed by a description of the changes, and changes in the grounds and migration methods
- Close Issue
If the current commit for a certain issue, you can turn off this issue in the Footer section (can turn over a closed issue
Closes #123, #245, #992
)
1.4 Revert
There is also a special case, if the current commit before the commit for revocation, it must revert: at the beginning, followed by the Header revoked Commit
revert: type(scope): some comment
This reverts commit bfe307ce57d87677c6c473c228e6c2ed8b81dcec.
Body section format is fixed, must be written This reverts commit <hash>.
, where the hash is withdrawn commit the HSHA
identifier.
If the current commit and commit revoked, in the same publication (release) inside, then they will not appear in the Change log inside. If they are in a separate publication, the current commit, it will appear in the Change log of Reverts subtitle below
2. Use commitizen to the implementation of norms
Because commitizen
that node
's the module, so the premise that you need to install the Node (official website to download address)
- Global installed
commitizen
node module
npm install -g commitizen
- Under the project directory run the command
commitizen init cz-conventional-changelog --save --save-exact
- At this point you may not find the reported
package.json
errors, use the following command to automatically generate a package of the project, and then run 2 commands.
npm init --yes
Runs out of use above all git cz
in place git commit
to submit code, and it will display the following options to automatically generate a formatted commit message.
PS D:\git\pythonPractice> git cz
[email protected], [email protected]
Line 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.
? Select the type of change that you're committing: (Use arrow keys)
> feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
test: Adding missing tests or correcting existing tests
(Move up and down to reveal more choices)
Follow the prompts, you can write a standard message
idea has plug-ins can use git commit template
commitizen also can check whether the commit message format
generated change log, but also has some advanced usage such as ghooks
will not elaborate here. See the detailed reference links and validate-commit-msg
- Now the project may be more out of
dir:node_nodules, file:package.json, package-lock.json
these directories and files, which are installed node module generates, if not the node item can be ignored, the students are familiar with node must know what is useful to the.
Reference links:
Ruan Yifeng 's blog
Jartto's blog
Reproduced in: https: //www.jianshu.com/p/55adc2330acd