Commit to introduce

Git must write a Commit message every time it commits code, otherwise it is not allowed to Commit.

$ git commit -m "commit message"
Copy the code
  • The -m parameter in the code above is used to specify the commit Message.
  • If one line is not enough, you can simply execute git Commit and the text editor will pop up and let you write multiple lines.
  • In general, the Commit message should be clear and state the purpose of the commit. It’s also easy to view the commit log when multiple people are collaborating.
  • There are currently several community specifications for how to write Commit messages. The Angular specification is currently the most widely used, reasonable and systematic. The diagram below:

Commit analysis

For each Commit, the Commit message consists of three parts: Header, Body, and Footer.

<header>

<body>

<footer>The Header is required, and the Body and Footer can be omitted.Copy the code

Don’t have too many characters on any line in any section. This is to avoid the aesthetics of wrapping.

Header

The Header section is a single line with three fields: Type (required), scope (impact, optional), and Subject (required).

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

type

Type is used to indicate the type of commit, and only the following seven identifiers are allowed (or, using the corresponding emoji, add another: to display).

The name of the instructions icon
feat New features
fix Fix the bug 🚑
docs Modify the document 📚
style Format code structure, no logical code changes. (e.g. white space, formatting, missing semicolons, etc.) 🎨
refactor Neither new features nor bug-fixing code changes, such as renaming variables) 🚜
test Add test code, unit test type, no production code changes) 🔬
build Changes that affect build systems or external dependencies (e.g., gulp, BROCCOLI, NPM)
ci Changes to Cl profiles and scripts (e.g., Travis, Circle, Browserstack, Saucelabs)
chore Do not modify SRC or other changes to the test file
revert Undo the last COMMIT

Revert: If the current COMMIT is used to undo a previous COMMIT, it must begin with Revert:, followed by the headers that have been undone.

revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
Copy the code

scope

Scope is used to define the scope that type affects, such as the data layer, control layer, view layer, and so on, depending on the project.

subject

Subject is a short description of the commit purpose, no more than 50 characters long.

Body

The Body section is a detailed description of the commit and can be divided into multiple lines, each line should be no longer than 72 characters. Note: You should explain the motivation for the code change and how it compares to previous behavior. Generally not written without major changes.

Footer

The Footer section is only used in two cases

  • Incompatible Changes: If the current code is incompatible with the previous version, the Footer section begins with BREAKING CHANGE, followed by a description of the CHANGE, the reason for the CHANGE, and the migration method.

  • Close Issue: If the current commit is for an Issue, you can close the Issue in the Footer section.

Closes #234
Closes #123, #245, #992
Copy the code

What is the use of so many specifications? If there are only two or three people working on a project, you don’t need strict specifications, you just need to write the submission clearly, but in a large project, there are many developers, and the submission is still necessary

Advantages of formatting a Commit Message

Provides more historical information for quick browsing

For example, the following command shows the changes since the last release, with each commit occupying one line. You know the purpose of a commit just by looking at the top of the line.

$ git log <last tag> HEAD --pretty=format:%s
Copy the code

Certain commits, such as document changes, can be filtered to make it easy to find information quickly

For example, the command below shows only the functionality added to this release

$ git log <last release> HEAD --grep feature
Copy the code

You can generate the Change log directly from the COMMIT (the Change log is a document that explains the differences from the previous version when a new version is released)