During team code reviews, the most headache-inducing thing is often not the code logic itself, but seeing a screen full of commit logs that look like:
updatefix bugtemp 123
This kind of “gibberish” turns historical backtracking into a detective game. Today, let’s talk about how to introduce Conventional Commits, making your Git history as clear as an instruction manual.
1. Why Do We Need Conventions?
- Automated Changelog Generation: With a standard format, scripts can automatically grab commits starting with
featto generate release notes. - Quickly Locate Issues: Seeing
fix(user-auth)tells you instantly that it fixes a bug in the user login module. - Trigger CI/CD: Certain types of commits (like
docs) can be configured to skip time-consuming build processes.
2. Standard Format
<type>(<scope>): <subject>
<body>
<footer>Structural Diagram
Header: feat(auth): add google login support │ │ │ │ │ └─ Subject (Short description) │ └─ Scope (Impact area, optional) └─ Type (Type: feature/fix/docs, etc.)
Body: (Empty line) Specifically, used the OAuth2.0 SDK. Added a new callback route.
Footer: (Empty line) Closes #123 (Associated Issue)2.1 Common Types
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Formatting changes (doesn’t affect code execution, e.g., spaces, semicolons)refactor: Refactoring (neither a new feature nor a bug fix)perf: Performance optimizationtest: Adding testschore: Changes to the build process or auxiliary tools
2.2 Examples
feat(login): add google oauth login support
fix(nav): fix navbar overlap on mobile screen
3. Tool Assistance: Commitizen
Don’t want to manually remember these rules every time? Use tools to enforce them.
Install commitizen:
npm install -g commitizenInitialize the adapter:
commitizen init cz-conventional-changelog --save-dev --save-exactWhen committing code in the future, don’t use git commit, but instead use:
git czIt will pop up an interactive interface guiding you to select the type and fill in the description.
4. Forced Validation: Husky + Commitlint
To prevent team members from “being lazy” and bypassing the conventions, you can intercept them in a Commit Hook.
- Install Husky and Commitlint.
- Configure the
commit-msghook.
When someone tries to submit an unstandardized message like git commit -m "update", Git will directly throw an error and reject the commit.
Common Errors and Solutions
-
Husky isn’t working?
- Ensure you have executed
npm installand the script triggeredhusky install. - In a CI environment, you might need to explicitly run
npm run prepare.
- Ensure you have executed
-
Garbage characters or line break issues on Windows
- Using
git czon Windows might result in emojis displaying incorrectly. It is recommended to use Windows Terminal or Git Bash, and set UTF-8 encoding.
- Using
-
Want to “escape” the convention?
- If you are really in a rush to fix a production bug and don’t want to fill out complex forms, you can use the
--no-verifyparameter to skip the check:git commit -m "hotfix" --no-verify - Note: Use with caution!
- If you are really in a rush to fix a production bug and don’t want to fill out complex forms, you can use the
5. Summary
Git records are the historical archives of a project. Writing standardized Commit Messages is a sign of respect for your teammates and a reflection of your own professionalism.
If this article helped you, please share it with others!
Some information may be outdated





