Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Git submission specification?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the Git submission specification". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, why do we need norms?

There are no rules, and so is programming.

If you have a project that you write yourself from beginning to end, you can write whatever you want, and no one can interfere with you. But if everyone shows off their individuality in teamwork, the code will be a mess and a good project will be ruined. Whether it is development or future maintenance, it will be a disaster.

At this time, someone proposed why we should not unify the standard, and everyone should follow this standard. As a result, code tools such as ESLint,JSHint are springing up like bamboo shoots after a spring rain and become essential products for project construction.

The Git Commit specification may not be that exaggerated, but you'll be annoyed if you see a lot of bad Commit when the version rollback. Therefore, strictly abide by the norms, benefit others and self-interest.

II. Specific rules

Let's take a look at the formula:

():

Type

Used to describe the category of commit, only the following seven identifiers are allowed.

Feat: new feature (feature)

Fix: patching

Bugdocs: document (documentation)

Style: format (changes that do not affect the running of the code)

Refactor: refactoring (that is, neither new features nor code changes to modify bug)

Test: adding tests

Chore: changes to the build process or aids

Scope

Used to describe the scope of commit impact, such as data layer, control layer, view layer, and so on, depending on the project.

Subject

Is a short description of the purpose of the commit, not exceeding 50 characters.

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Start with a verb and use the personal present tense, such as change, instead of changed or changes

* lowercase letters

There is no full stop at the end.

Third, exception handling

Let's first take a look at this abnormal reminder:

INVALID COMMIT MSG: does not match "():"! Jartto:fix bug

This warning is reported here because there are two problems with my submission:

First, keywords outside the specification are used.

Second, very detailed questions, jartto: missing spaces

It was only then that I recalled that the submission had failed all the time, and it was forced to submit directly in an urgent situation, so later submissions would bring out this exception. It roughly means:

Your previous Commit is not qualified ~ your previous Commit is not qualified ~ your previous Commit is not qualified.

At this time, it is very annoying, we can only correct the previous errors, so how to do it?

4. How to modify the previous commit information?

It's not complicated, we just need to do this:

1. Temporarily store the working status independent of the current branch.

Git stash

2. Move HEAD to the commit that needs to be modified

Git rebase 9633cf0919 ^-- interactive

3. Find the commit to be modified, and change the pick in the first line to edit.

Start working on your bug

5. Git add adds the change file to the temporary storage

6. Git commit-amend appends changes to submission

7. Git rebase-continue: move HEAD back to commit of *

8. Restore the previous state of work

Git stash pop

It's done. Do you want to modify the whole Commit and escape?

V. use in the project

At this time, the question comes again, why do I have a warning when I submit it, and how do I do this?

At this point, we need a Node plug-in validate-commit-msg to check whether the Commit message in the project is standardized.

1. First, install the plug-in:

Npm install-save-dev validate-commit-msg

two。 First, create a .vcmrc file:

{"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"], "scope": {"required": false, "allowed": ["*"], "validate": false, "multiple": false}, "warnOnFail": false, "maxSubjectLength": "subjectPattern": ". +", "subjectPatternErrorMsg": "subject does not match subject pattern!", "helpMessage": "," autoFix ": false}

3. Mode 2: write to package.json

{"config": {"validate-commit-msg": {/ * your config here * /}

4. But what if we want to use the ghooks hook function automatically?

{... Config: {"ghooks": {"pre-commit": "gulp lint", "commit-msg": "validate-commit-msg", "pre-push": "make test", "post-merge": "npm install", "post-rewrite": "npm install",... }}. }

There are a lot of things we can do in ghooks, not just validate-commit-msg.

For more details, please refer to validate-commit-msg

VI. The function of Commit specification

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

Provide more information to facilitate troubleshooting and fallback

Filter keywords and locate them quickly

Easy to generate documents

7. Generate Change log

As mentioned above, it is easy to generate documentation if our submissions follow the specification. The generated document consists of the following three parts:

New features

Bug fixes

Breaking changes.

Each section lists the relevant commit and has links to these commit. Of course, the generated document allows manual modification, so you can add other content before release.

Here you need to use the tool Conventional Changelog to generate Changelog:

Npm install-g conventional-changelog cd jartto-domo conventional-changelog-p angular-I CHANGELOG.md-w

For ease of use, you can write it to the scripts field of package.json.

{"scripts": {"changelog": "conventional-changelog-p angular-I CHANGELOG.md-w-r 0"}}

In this way, it is easy to use:

This is the end of npm run changelog's "what is the Git submission specification". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report