The background,
Git commits every time you write a commit message. In general, the commit message should be clear, stating the purpose of the commit, the specific operation, and so on. However, in daily development, the developers submit strange commit messages, which are mixed in Chinese and English, resulting in high maintenance costs for subsequent code, and sometimes they do not know what problem their fix bug fixes are. Based on the above problems, we hope to monitor the git commit message of users in some way, so that the specification can better serve the quality and improve the r&d efficiency of everyone.
Second, the convention
The format of the Commit Log for all projects is precisely controlled to increase readability, make it easy to view the change history, and form a good git habit. The git hook specification is executed as commit-msg and pre-receive. After full execution, the following operations can be performed automatically:
- The platform toolkit can generate each Version of Changelog based on the Commit log.
- The system automatically provides the commit log for this online application.
- Think carefully about each commit, keep the commit log clean, and keep the local integrity of each commit.
Commit Log Format
The Commit Log contains three parts: header, body, and footer. The header is mandatory and the format is fixed. The body is used when the change is necessary to explain in detail.
The commit log format
Plain Text
< types > (< scopes >) : < subject > line < empty > < body > < empty line > < footer >Copy the code
Note: The colon must be followed by a lowercase space, and multiple types and scopes can be separated by commas.
For example:
-
Only the header:
Service (DAO) (fix): The product Type is not filtered when the product Type is changedCopy the code
-
Only header is used. Most modules involved are replaced with *
Refactor (*): Modifies the DTO model prefixCopy the code
-
Have the header and body
fix(language-service): Improve signature selection for pipes with args
Pipes with arguments like `slice:0` or `slice:0:1` should not produce
diagnostic errors.
Copy the code
-
There are header, body, and footer
Func (core logic) : add a gift bag Add commodity editors state and callback, blablablabla PRD:https://km.sankuai.com/page/194127085Copy the code
1, the Type,
English, lowercase. Must be one or more of the following:
- Func: function. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Fix: bug fixes, including logical fixes during coding, not specifically online bug fixes
- Refactor: Refactoring code, non-bug fixes and performance optimizations, including code structure adjustments during coding, not specifically refactoring projects
- Impr: Improvement, small code design improvement
- Perf: Performance optimization
- Apm: only monitors log processing and exception log processing
- Chore: trivial changes, such as removing unwanted notes, adjusting log content, etc
- JVM: Only JVM parameters change
- Pom: Dependency and version change only
- Conf: Configuration changes only, Spring configuration, properties files
- Docs: Only documents are changed
- Style: Code formatting adjustments, such as import cleanup, code formatting
- Test: Single test related to automated case
- Typo: Fixes small spelling mistakes
- Wip: Work in Progress, used sparingly, for incomplete submissions in development, occasionally at the start of a new project
2, the Scope,
English, lowercase. Indicates the range of packages or modules to be changed. Multiple combinations can be used. If a larger range is involved, * can be used instead. Each service can be defined by itself, which can be easily understood by students in the group. The general scope list is as follows:
- Dto: DTO structure changes
- The core: the core packages
- Service: Service layer code
- Dao: Dao layer code
- SQL: SQL code changes
In addition to the above general fields, each direction in Scope can define its own keywords. For example, the following fields are defined in the commodity platform:
- Price: Price is related
- Stock: Inventory related
- Product: Commodity related
- Idl: idL file changes
3, the Subject
In Chinese. Modify the title summary without a period at the end.
4, the Body
In Chinese. The background of the change (why the change was made) and the logic of the change.
5, and Footer
In Chinese. You can place a wiki or task link that will be useful for other students to blame later.
Four, standard verification
Commit log regular expressions (used by continuous integration tools) :
Java code block
(^(\w+)\(([\w+,.\-_*]+?) \): .+(.|\n)*)|(^Automatic merge(.|\n)*)|(^Merge (.|\n)*)Copy the code
2. Local card control
- Local hook: you can add a git hook to ensure that the illegal commit log format cannot be submitted, and execute it in your own project:
#! /usr/bin/env python import sys, os, re from subprocess import check_output commit_msg_filepath = sys.argv[1] commit_type = sys.argv[2] if len(sys.argv) > 2 else '' branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip() print "commit_type:", commit_type with open(commit_msg_filepath, 'r+') as f: content = f.read() # ignore merge if content.startswith('Merge'): sys.exit(0) result = re.match('(\w+)\(([\w+,.\-_*]+?) \): .+(.|\n)*)', content) if result is None: print "ERROR: commit msg not match pattern '<type>(<scope>): <subject>'\n\t%s" % content sys.exit(1) sys.exit(0)Copy the code
Then execute in git repository level 1 directory:
mv commit-msg.txt .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
Copy the code
Five, the statement
This article authorized public number: naked eye product world first
Original link: lesofn.com/archives/me…
Author’s brief introduction
Meituan Java senior engineer, focus on software architecture and career growth, share various technologies and resources from time to time, interested in the technology involved in the article or have any questions, please follow the wechat exchange.
Public id: Java development