Git commit规范

241 阅读1分钟
commit格式规范插件:
cz-customizable

需要配置.cz-config.js

cz-customizable

1. 确保代码提交前 eslint、stylelint 的 warnings 和 errors 清零

2. 目录、文件 - 命名规则

RawcamelCasePascalCasekebab-case ⭐
fruits in basketfruitsInBasketFruitsInBasketfruits-in-basket
has errorhasErrorHasErrorhas-error
is visibleisVisibleIsVisibleis-visible
  1. 优先使用 kebab-case (全小写加中划线) 的方式命名(参考element), 如: service-worker, ant-design, react-dom.
  2. 组件的默认入口为 index.tsxindex.js, 如: footer/index.tsx, header-search/index.tsx

3. git 分支规范

4. git config 全局设置

配置拉取远程分支代码时默认 rebase

git config --global pull.rebase true

配置大小写敏感

git config --global core.ignorecase false
git config core.ignorecase false # 非必要, 看情况是否需要覆盖原配置

配置用户名和邮箱 (以 wangwu06 为例)

git config --global user.name "wangwu06"
git config --global user.email "wangwu06@huice.com"

5. git commit message 前缀

feat: 新功能(feature)
fix: 解决bug
docs: 文档(documentation)
style:  格式(不影响代码运行的变动)
refactor: 重构(即不是新增功能, 也不是修改bug的代码变动)
test: 增加测试用例
chore: 构建过程或辅助工具的变动
i18n: 更新多语言资源文件(internationalization)
perf: 性能优化(performance)

示例

git commit -m 'feat: 添加登录页' .
git commit -m 'fix: 登录失败' .
git commit -m 'fix: editor - detail-panel - data error' .
git commit -m 'doc: update readme' .

6. 提交本地代码改动至远程仓库

# 1. 查看、确定本地文件改动
git status
# 2. 查看具体改动内容
git diff
# 3. 确认无误后
git add .
# 4. 提交代码至本地仓库 (推荐 git cz ✨)
git cz
# 或
git commit -m 'message' .
# 5. 拉取远程代码
git pull --rebase
# 6. 推送代码至远程仓库
git push

7. 推荐使用SFC新语法糖 <script lang="ts" setup>

8. 微前端项目命名规则

子应用:

dolphin-app-<AppName>

插件:

dolphin-plugin-<PluginName>