Git: teach you how to have something to say when committing

Git: teach you how to have something to say at Commit

I don’t know if you have ever observed those projects that are among the top Stars on Github. They all have a complete documentation system and high coverage test cases. To achieve perfection, it is definitely impossible to have no standard. The code must have the code standard, and the collaboration must have the cooperative standard. The topic we are going to talk about today is the reference specification for recording Commit Message in Git. Let's take a look at two pictures, one is from a well-known international project and the other is a well-known domestic project (laughs).

Internationally renowned project AngularJS

Insert picture description here
Insert picture description here

From the above two pictures, I think you can already see some clues. In comparison, it is self-evident which one can promote development. Of course, I cite this well-known domestic project as extreme, but on the whole, Commit Messages are more casual.

Commit specification

Following the train of thought, this step should give a plan. The plan is the Git Commit Guidelines used in the AngularJS project above.

Commit Message format

<type>(<scope>): <subject>
<空行>
<body>
<空行>
<footer>

The above is the message format specification after a Commit, which is divided into three parts: title, content details, and ending. Each has its own use and no extra items.

The header is the first line, which can be previewed directly on the page. As shown in the figure above, there are three parts, and the meanings are as follows

Type
  • feat: new features (feature)

  • fix: fix bug

  • docs: documentation

  • style: Format (does not affect changes in code operation)

  • refactor: refactoring (that is, it is not a new feature, nor a code change to modify a bug)

  • test: add test

  • chore: changes in the build process or auxiliary tools

Scope

Used to explain the scope of the impact of this Commit, that is, to briefly explain the parts involved in the modification. This was originally an optional item, but it can be seen from the actual AngularJS project that it has basically become a required item.

Subject

Used to briefly describe this change, just an overview, because specific information will be given in the Body later. And it is best to follow the following three:

  • Begin with a verb and use the first-person present tense, such as change, not changed or changes

  • Don't capitalize the first letter

  • Do not end with a period (.)

Body
The content here is an expansion of the content in the above subject. Here is a more detailed description. The content should include the motivation for the modification and the comparison before and after the modification.
Revert

In addition, if you need to cancel the previous Commit, then this Commit Message must revert:start with, followed by the Header part described earlier, and the format remains unchanged. In addition, the format of the Body part is also fixed, and the SHA value of Commit before the revocation must be recorded.

Practice tool

The above is the current Commit specification of AngularJS. I believe it will be a bit big when you first contact it. At this time, if there is any Step by Step reminder or visual demonstration, it would be great. OK, you have come to the right place, now let's talk about the specific steps how to turn the specification into executable!

Install the tool Commitiz

In order for us to apply these specifications to actual use, we have to use Commitizenthis Node tool, which will guide us step by step how to implement the specifications step by step with more standardized content during our Commit process. Of course, there is no unique standard for this kind of thing. Each company has its own differences. Of course, this is also thought of by the tool. You can also customize your own specifications and let Commitizen follow your own specifications in the form of plug-ins. remind you.

installation
npm install -g commitizen
Configuration

In the previous step, we installed commitizen globally, and then we can configure our Commit specification in the Git repository. Open the project and execute the following commands:

commitizen init cz-conventional-changelog --save --save-exact

The above cz-conventional-changelog is the AngularJS specification. You can find other specifications on the official website by yourself. If not, take the time to draw up a copy. This command helps you to download the cz-conventional-changelog specification, configure package.json (add dependency and configure application specification), and open package.json if you want to see specific changes.

use

At this point, even if the installation is complete, you can call out the interactive interface of Commit by git commitreplacing it with git czinstructions where needed , and come to step by step to remind you how to fill in the above specifications. It is not clear how to build a project yourself. Enough. It's a pity that I didn't see the classmates at the end of the article by posting a moving picture. (PS: I think it's useful to forward it)

You can also watch:

Git: Talk about the Rebase command

Git: How to Commit Safely

Git: How to perform a "git pull" operation gracefully

Git: "Small Step Run" development model

Git: Ignore files that have been committed

Git: rewrite commit history

Git: How to use Submodules correctly in your project

reference

https://www.cnblogs.com/Irving/p/5146738.html

Guess you like

Origin blog.csdn.net/qq_42648305/article/details/113103925