How to write a Commit message to make it clearer? Have you ever had a Frustrating Git commit in your team’s development? This article shares practices in git commit specification construction, specifying the format of the commit message, and monitoring the commit through Webhook to avoid non-standard code commit.

background

Git must write a commit message every time it commits code, otherwise it will not commit. In general, the commit message should be clear, stating the purpose of the commit, what it did… However, in daily development, people’s commit messages are very strange. It is common to use mixed Chinese and English messages, fix bugs and other general messages. As a result, the maintenance cost of subsequent code is very high, and sometimes I don’t know what problem my fix bug fixes. 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.

Specification introduce

Let’s start with the AngularJS specification, which is the most widely used standard for submitting messages by Google. A reasonable set of manuals is more systematic; And there are tools available for us to use.

To put it bluntly, a specification is a tool with strong constraints. The implementation plan of the specification is as follows:

Now that you have a solution, you follow certain rules. Here are the requirements of the Google AnguarJS specification:

Standard target

– Allows script generation of Changelog.md

– You can quickly search to the specified version by keyword of the range

Git log HEAD --grep package.jsonCopy the code

Format requirements

<type>(<scope>): <subject>
  <BLANK LINE>
      <body>
  <BLANK LINE>
<footer>
Copy the code

– The message takes only one line, and no line can exceed 100 characters

– Allows you to read messages using GitHub and various Git tools

– The submit message consists of a header, body, and footer, separated by blank lines

Represents the type of a commit, such as fixing a bug or adding a feature, as follows:

The scope can be anything that specifies where to commit changes, such as:

– Add a dependency library to package.json file, and chore(package.json): Adds a dependency library

– Refacto (weixin. Vue): Refacto (weixin. Vue): Refacto (weixin

If you don’t have a more appropriate scope, you can just write the submission

Standard construction

We did a lot of research on git Commit specifications on the Internet, but only the Angular specification is the most widely used, systematic, and tool-supported (IDEA has plug-ins to support this). Finally, a set of Git commit specifications is summarized based on the existing specifications of alibaba Amap related departments.

A commit message format

<type>(<scope>): <subject>
Copy the code

conclusion

Code specification, process specification is very important in software development process, it can save us a lot of detours in the development process. The Git commit specification is the same, and indeed necessary, as it takes little extra effort and time to find problems later on. As a programmer, we should pay more attention to the standardization of code and process, never in quality.

How to standardize your Git commit?