mcpField
G
git-commit

git-commit

github.com/ilteoood开发2548 次安装6 天前更新
代码仓库

关于 git-commit

用于按 Conventional Commits 格式创建语义化 Git 提交的 Skill。它依据实际差异确定类型、范围和描述,并提供暂存建议及 Git 安全规则。

主要功能

  1. 01分析已暂存或工作区差异
  2. 02选择提交类型、范围和描述
  3. 03提供暂存与信息格式建议
  4. 04包含机密信息和破坏性命令防护

适用场景

  1. 01根据代码变更准备语义化提交
  2. 02选择提交类型和范围
  3. 03提交前检查 Git 安全事项

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ilteoood/harness --skill git-commit

安装后在 Claude Code 中输入/git-commit确认已加载。

详细介绍

使用约定式提交进行 Git 提交

概述

使用约定式提交(Conventional Commits)规范创建标准化、语义化的 git 提交。分析实际差异以确定合适的类型、范围和提交信息。

约定式提交格式

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

提交类型

类型用途
feat新功能
fix缺陷修复
docs仅文档
style格式/样式(不涉及逻辑)
refactor代码重构(非功能/修复)
perf性能优化
test新增/更新测试
build构建系统/依赖
ciCI/配置变更
chore维护/杂项
revert回滚提交

破坏性变更

# Exclamation mark after type/scope
feat!: remove deprecated endpoint

# BREAKING CHANGE footer
feat: allow config to extend other configs

BREAKING CHANGE: `extends` key behavior changed

工作流

1. 分析差异
# If files are staged, use staged diff
git diff --staged

# If nothing staged, use working tree diff
git diff

# Also check status
git status --porcelain
2. 暂存文件(如需要)

如果没有任何内容被暂存,或你想以不同方式对变更进行分组:

# Stage specific files
git add path/to/file1 path/to/file2

# Stage by pattern
git add *.test.*
git add src/components/*

# Interactive staging
git add -p

绝不要提交机密信息(.env、credentials.json、私钥)。

3. 生成提交信息

分析差异以确定:

  • 类型:这是哪种变更?
  • 范围:影响哪个区域/模块?
  • 描述:变更内容的一行摘要(现在时、祈使语气、<72 字符)
4. 执行提交
# Single line
git commit -m "<type>[scope]: <description>"

# Multi-line with body/footer
git commit -m "$(cat <<'EOF'
<type>[scope]: <description>

<optional body>

<optional footer>
EOF
)"

最佳实践

  • 每次提交一个逻辑变更
  • 使用现在时:"add" 而非 "added"
  • 使用祈使语气:"fix bug" 而非 "fixes bug"
  • 引用议题:Closes #123、Refs #456
  • 描述保持在 72 字符以内

Git 安全协议

  • 绝不更新 git 配置
  • 未经明确要求,绝不运行破坏性命令(--force、hard reset)
  • 除非用户要求,绝不跳过钩子(--no-verify)
  • 绝不强制推送到 main/master
  • 如果因钩子导致提交失败,修复后创建新提交(不要使用 amend)

评论

支持 Markdown