claude code中添加skills自动生成git commit信息

claude code中添加skills自动生成git commit信息

git-commit-helper

这个 git-commit-helper skill 的作用是:读取 staged changes,也就是已经 git add 的改动,然后根据 git diff --staged 生成规范的 commit message

这个 skill 会用 Bash 执行

bash 复制代码
git diff --staged --name-only
git diff --staged

它的分析流程里明确写了先检查 staged changes,再分析改动内容。 所以如果你的 .claude/settings.json 完全禁止 Bash,这个 skill 就无法自动读取 diff

1.1 git-helper这个skill适合解决什么问题

Claude 修改完代码后,我不知道 git commit message 应该怎么写

这个 skill 正好适合放在修改完成后使用:

Claude 修改代码

→ 你检查 git diff

→ 你 git add 需要提交的文件

→ 调用 /git-commit-helper

→ Claude 生成 commit message

→ 你手动 git commit

不要让 Claude 自动执行 git commit。让它只生成 message,你自己复制执行最稳。

1.2 安装方式:只给当前项目使用

把 skill 放到项目级 .claude/skills 目录

bash 复制代码
your-project/
├── CLAUDE.md
├── .claude/
│   ├── skills/
│   │   └── git-commit-helper/
│   │       └── SKILL.md
│   └── settings.json
├── main.py
├── utils/
└── configs/

Claude Code 官方文档说明,项目级 skill 路径是:

bash 复制代码
.claude/skills/<skill-name>/SKILL.md

只对当前项目生效;

个人级 skill 路径是:

bash 复制代码
~/.claude/skills/<skill-name>/SKILL.md

会对所有项目生效

1.3 skill.md内容

bash 复制代码
---
name: git-commit-helper
description: Generate clear Conventional Commit messages from staged git changes. Use after code modifications when the user asks what commit message to write. Analyze staged diff and suggest commit messages only. Do not execute git commit.
allowed-tools: Bash, Read
disable-model-invocation: true
---

# Git Commit Helper

你是当前项目的 Git commit message 助手。

你的任务是:根据 staged changes 生成清晰、准确、可复制的 commit message。

## 严格规则

- 只生成 commit message。
- 不要执行 `git commit`。
- 不要执行 `git push`。
- 不要执行 `git add`。
- 不要修改任何文件。
- 不要为了生成 message 改代码。
- 如果没有 staged changes,提醒用户先手动执行 `git add <file>`。
- 如果 staged changes 过多,先建议用户拆分提交。

## 允许读取的信息

优先读取 staged changes:

```bash
git status --short
git diff --staged --name-only
git diff --staged

1.4 git commit格式

使用 Conventional Commit 格式:

bash 复制代码
<type>(<scope>): <subject>

<body>

常用 type:

bash 复制代码
feat: 新增功能
fix: 修复 bug
refactor: 重构,不改变默认行为
perf: 性能优化
docs: 文档修改
test: 测试相关
style: 格式或排版,不改变逻辑
chore: 工程维护、配置维护、依赖或杂项
config: 配置参数调整
experiment: 实验流程或评估脚本调整

根据修改文件选择 scope:

例如我的项目

bash 复制代码
frontend: utils/slam_frontend.py
backend: utils/slam_backend.py
loop: utils/loop_closure.py

Subject 规则

使用英文

使用祈使句

小写开头

不超过 72 个字符

不以句号结尾

准确描述本次提交的核心变化

例子

bash 复制代码
fix(submap): preserve global seed pose when starting new submap
feat(config): add synchronized submap pruning parameters
refactor(loop): separate adjacent odometry from loop closure edges
docs(claude): add base config synchronization rule

Body 规则

Body 用英文 bullet points,说明 what 和 why,不要详细复述代码实现。

示例

bash 复制代码
- Keep submap initialization aligned with the tracked global pose
- Avoid resetting pose state during submap transitions
- Preserve compatibility with existing checkpoint fields

完整commit输出格式

Recommended commit message

<完整 commit message>
Alternative messages

type(scope): subject

type(scope): subject

type(scope): subject
Why this message

改动类型:

推荐 scope:

核心原因:

是否包含 breaking change:

是否建议拆分提交:

1.5 配置claude权限只能读git diff 不能执行git commit

bash 复制代码
.claude/settings.json
bash 复制代码
{
  "permissions": {
    "allow": [
      "Read(*)",
      "Bash(git status:*)",
      "Bash(git diff:*)"
    ],
    "deny": [
      "Bash(git commit:*)",
      "Bash(git push:*)",
      "Bash(git reset:*)",
      "Bash(rm -rf:*)"
    ]
  }
}

含义是:

bash 复制代码
允许:
- 读取文件
- 查看 git status
- 查看 git diff

禁止:
- git commit
- git push
- git reset
- 删除文件
- 编辑文件
- 写文件

1.6 如何使用

(1)让claude修改代码

(2)修改完成后,先让它总结:

bash 复制代码
请总结本次修改的 git diff,不要提交。

(3)自己在终端里手动运行检查diff

bash 复制代码
git status
git diff

确认claude没有乱改动要求范围外的代码

(4)自己 stage (将修改代码添加到本地暂存区)文件

bash 复制代码
git add utils/slam_frontend.py
git add utils/slam_backend.py
git add configs/rgbd/tum/base_config.yaml
git add configs/rgbd/replica/base_config.yaml
git add configs/rgbd/scannetpp/base_config.yaml

(5)调用 skill

在 Claude Code 中输入:

bash 复制代码
/git-commit-helper

或者更明确:

bash 复制代码
/git-commit-helper 请分析 staged changes,只生成 commit message,不要执行 git commit。

(6)复制 Claude 给出的 commit message后自己手动执行commit

bash 复制代码
git commit -m "fix(submap): preserve global pose during submap transition" -m "- Initialize new submaps from the tracked global camera pose
- Keep frontend and backend pose semantics aligned
- Avoid pose jumps when cutting submaps"
相关推荐
取个鸣字真的难11 小时前
OpenYabby 深度解读:一个语音驱动的开源多智能体项目执行系统
多智能体·ai agent·claude code
qq_3384323712 小时前
VS Code 远程 WSL 中 Claude Code 导致 Java 文件修改被自动撤回的一次排查
vscode·vibe coding·claude code
我家媳妇儿萌哒哒12 小时前
git:无法推送refs到远端。您可以试着运行“拉取”功能,整合您的更改。
git
驯龙高手_追风15 小时前
Gitlab本地服务器搭建及配置-详细教程
git·github
czhc114007566316 小时前
6.11:halcon,Sqlserver;项目sql连接;git
git·sql·sqlserver
炸炸鱼.17 小时前
Git+Jenkins 基本使用:从入门到实战(知识点大全)
运维·git·jenkins
戴国进19 小时前
git stash 用法详解
git
木雷双雄720 小时前
Git 版本回退操作指南
git
jike88ai20 小时前
Claude Code完整安装+API配置教程(Windows系统)
windows·gpt·node.js·claude·api中转·claude code·88api
m0_579146651 天前
已被 Git 追踪的本地修改文件如何实现临时忽略
git