Git项目管理

使用Git提交模板

  1. 项目根目录下创建提交模板

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    cat > .gitmessage << 'EOF'
    # ============= Git 提交信息模板 =============
    # 类型(必填): feat | fix | docs | style | refactor | perf | test | chore | ci | build | revert
    # 影响范围(可选): 例如模块、组件或功能(如 "user-auth", "payment-api"
    # 描述(必填): 简洁说明本次提交的更改
    # --------------------------------------------

    <类型>(<影响范围>): <简短描述>

    # 详细说明(可选):
    # - 为什么进行这次更改?
    # - 解决了什么问题?
    # - 是否有副作用或注意事项?

    # 关联 Issue 或 Task(可选):
    # Fixes #123
    # Closes #456
    # Related to #789

    # -------------------- 示例 --------------------
    # feat(user-auth): 添加 OAuth2 登录支持
    #
    # - 集成 Google 和 GitHub OAuth2 登录
    # - 更新用户模型以存储第三方登录信息
    #
    # Fixes #42
    # Related to #56
    # =============================================
    EOF
  2. 配置当前项目使用模板提交(项目成员都需配置)

    1
    git config --local git commit.template=.gitmessage
  3. 创建强制检查脚本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    mkdir .githooks
    cat > commit-msg << 'EOF'
    #!/bin/bash
    MSG_FILE="$1"
    MSG=$(cat "$MSG_FILE")

    # 检查是否包含类型和描述
    if ! echo "$MSG" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)\(.*\): .+"; then
    echo "错误:提交信息不符合规范!"
    echo "示例: feat(user-auth): 添加登录功能"
    exit 1
    fi
    EOF
    chmod +x .githooks/commit-msg
  4. 配置强制检查提交格式(项目成员都需配置)

    1
    git config --local git core.hookspath=.githooks
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2015-2025 Kaisar
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信