Since the company hasn’t stipulated a code submission specification since I joined the company, I have been submitting code for a long timecommit message
It is a simple sentence that explains the content of this code change. Sometimes it will be more concise.
But after a long time, when I need to look back for a submitted record, I will find it difficult to find. First of all, there is no specific classification, such as adding functions, repairing bugs, or updating documents; Secondly, there are somemessage
The writing is not very clear, so I can’t see what the changes were.
Later, I decided that I needed to learn more aboutcommit message
Specification for the writing of.
Benefits of commit message
- Of each submitted record
message
It can provide more effective information for us to browse quickly; - have access to
git log --grep <keyword>
Filter out somecommit
, which is easy to find information quickly; - Can be directly from
commit
generateChange log
。
Commit message format
at presentCommit Message
The most commonly used specifications areSpecifications of angular teamAnd then derivedConventional Commits sepcification。
Commit Message
It consists of three parts:Header
、Body
andFooter
。 The format is as follows:
<type>(<scope>): <subject>
< blank line >
<body>
< blank line >
<footer>
Of which,Header
Is required,Body
andFooter
It can be omitted.
Header
Header
It consists of three parts:type
、scope
andsubject
。 amongscope
Is optional.
<type>(<scope>): <subject>
# example
feat($route): add support for the `reloadOnUrl` configuration option
type
type
Yes for descriptioncommit
The specific identification is as follows:
feat
: a new feature(feature
);fix
: repairbug
;docs
: modify the document, such asREADME.md
、CHANGELOG.md
Etc;style
: modify the format of the code without affecting the code operation, such as spaces, formatting codes, complementing semicolons at the end of sentences, etc;refactor
: code refactoring, no addition of new functions and code changes for bug repair;perf
: optimize code to improve performance;test
: add tests or optimize and improve existing tests;build
: modify external dependencies that affect the project build file, such asnpm
、gulp
、webpack
、broccoli
Etc;ci
: modify CI configuration files and scripts;chore
: modification of other non SRC path files and test files, such as.gitignore
、.editorconfig
Etc;revert
: Code fallback;
scope
scope
Yes for descriptioncommit
The scope of influence, such as data layer, control layer, view layer, etc., varies according to the project.
If your changes affect more than onescope
, you can use*
Substitute.
subject
subject
yescommit
The purpose of is a simple description, no more than 50 characters, and the end does not need a period.
Body
Body
Part is about thiscommit
Can be divided into multiple lines.
Body
The section should explain the motivation for the code change and the comparison with the previous behavior.
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Use a hanging indent
Footer
Footer
This section is mainly used in two cases: incompatible changes and processingIssue
。
Incompatible changes
If the current code is not compatible with the previous version, thenFooter
Partially byBREAKING CHANGE:
At the beginning, the following is the description of the change, the reason for the change and the migration method.
BREAKING CHANGE: Previously, $compileProvider.preAssignBindingsEnabled was set to true by default. This means bindings were pre-assigned in component constructors. In Angular 1.5+ the place to put the initialization logic relying on bindings being present is the controller $onInit method.
To migrate follow the example below:
Before:
```js
angular.module('myApp', [])
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.doubleValue = this.value * 2;
}
});
```
After:
```js
angular.module('myApp', [])
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.$onInit = function() {
this.doubleValue = this.value * 2;
};
}
});
this.doubleValue = this.value * 2;
};
}
});
```
Don't do this if you're writing a library, though, as you shouldn't change global configuration then.
Process issue
If currentcommit
Is for processing aissue
, then you canFooter
Partially dimensionedissue
。
Fixes #234
If you want to close thisissue
If:
Closes #234
Related plug-ins
Commit – quickly write a commit message
We can use third-party plug-insCommitizen
To quickly write ourCommit Message
。
First, install it globallyCommitizen
。
npm i -g commitizen
Then, under our project path, run the following command to make it supportAngular
ofCommit Message
Format.
commitizen init cz-conventional-changelog --save --save-exact
After the installation, each time we submit the code, we will no longer use itgit commit -m
Command, but usegit cz
To perform the operation.
git cz
First selectCommit Type
, and then press enter to confirm.
[email protected], [email protected]
? 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, for
matting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
(Move up and down to reveal more choices)
Then enterscope
Information for.
What is the scope of this change (e.g. component or file name): (press enter to skip)
Then entersubject
Information.
Write a short, imperative tense description of the change (max 85 chars):
Following configurationBoby
Information for.
Provide a longer description of the change: (press enter to skip):
? Are there any breaking changes? Yes
? A BREAKING CHANGE commit requires a body. Please enter a longer description of
the commit itself:
Final configurationFooter
Information.
Describe the breaking changes:
? Does this change affect any open issues? Yes
? Add issue references (e.g. "fix #123", "re #123".):
Commitlint – verify your commit message
Commitlint
Can help us checkCommit Messages
, if our submission does not conform to the specification pointed to, it will be rejected directly.
Therefore, we also need to provide it with a verification configuration, which is recommended here@commitlint/config-conventional(in accordance with angular team specifications).
Installation:
npm i -D @commitlint/config-conventional @commitlint/cli
At the same time, you need to create a configuration file under the project directory.commitlintrc.js
, write:
module.exports = {
extends: [
"@commitlint/config-conventional"
],
rules: {}
};
For more relevant configurations, please refer to the official documentation.
Standard Version – automatically generate changelog
When ourCommit Message
If we meet the standard of angular team, we can usestandard-version
Such tools can automatically generate changelog and even semantic version numbers(Semantic Version)。
Installation:
npm i -S standard-version
package.json
to configure:
"scirpt": {
"release": "standard-version"
}