Voting portal

1. Introduction

Most companies now use Git as version control, and every programmer commits code on a daily basis. A lot of developers, myself included, sometimes in a hurry or just to save the day, commit like this:

git commit -m "Fix bugs, optimize code."
Copy the code

After a while, suddenly look up a specific submission and you’ll find that it’s not particularly easy to find. So we need to standardize our code commit to avoid this. At the same time, a good submission specification also helps us to generate a clear ChangeLog, which is more conducive to collaboration among colleagues.

If you want to be a contributor to a well-known open source project, you should also standardize your code submissions.

2. Git commit specification

One of the best references in the industry is the submission specification of the well-known front-end framework AngularJS. Let’s start with an example:

The corresponding format:

<type>[optional scope]: <description>
# a blank line
[optional body]
# a blank line
[optional footer]
Copy the code

More stringent project submissions may require an English description, especially for internationalized open source projects.

Let’s take a look at the Git commit specification that is widely accepted in the industry.

type

Refactor indicates that the refactoring code is submitted, which means that it is a submitted type. In addition to Refactor, there are:

  • featNew functionality, as the name implies, is the implementation of new requirements.
  • fixA fix is a fix for a bug.
  • docsDocument, mainly used to describe changes to the document.
  • styleMainly code style related submissions, such as formatting and so on.
  • refactorRefactoring code, refactoring existing functionality, but different from bugfix.
  • testTest related commits, less commonly used.
  • choreLess common changes to the build process or auxiliary tools, such as Gradle instead of Maven.

It is necessary to declare the type of submission for each submission, so that the purpose of the submission is clear.

Scope (Optional)

It is used to indicate the scope of the impact of this submission for quick positioning. You can specify which module (usually the module name) or which layer (data layer, service layer, or view layer) is affected.

subject

It is the modification copyright information above, which is a brief description and summary of this submission. Just like Fat brother writing a title, not too long.

Body (optional)

This is to describe the items involved in this submission in detail and list the code functions. Here, the big man used markdown’s list syntax, which is to separate the items with a hyphen and a newline. Of course, the body is not required, if the subject can be described clearly.

Foot (optional)

Describe the break change or issue associated with this submission.

break change

Indicates whether the commit has generated destructive modifications, such as version upgrade, interface parameter reduction, interface deletion, and migration. In case of the above impact, it is strongly recommended to specify break change in the submission information, which is conducive to quick positioning, rollback and recovery when problems occur.

issue

If you find bugs in your project, or you have suggestions for optimizing it, or even add a new task, you can use the issue to submit a task to your project.

Issue is not a feature that is exclusive to some Git platforms. JIRA and others have similar features that serve a similar purpose and are a good indicator of a project’s growth and engagement. So when committing Git, we can associate the issue involved in the commit in the foot area.

Watch-watches #F12YC #F45JW # watch-watches #F12YCCopy the code

There is no set format, but try to refer to some well-known projects.

3. Tools amway

With all this said, you should have some idea of the specification for Git commits. Here are some useful tools to help you put these specifications in place. In the Intellij IDEA plug-in market, there are many Git Commit Message template plug-ins that visually implement these specifications.

You can search the plugin market for relevant plug-ins. Good today’s share here, more attention: code farmer little fat brother, learn more useful programming practical skills.

Follow the official account Felordcn for more information

Personal blog: https://felord.cn