| name | commit-push |
| description | Create a git commit and optionally push to origin/master for the Keeper_CoC-TRPG project. Trigger when the user explicitly asks to commit, push, "提交", "推送", or "上传到 GitHub". Follows Conventional Commits (English) style, never auto-commits without an explicit request, and refuses destructive operations (force-push, --no-verify, --amend on pushed commits, git config changes). |
commit-push
为 Keeper_CoC-TRPG 项目执行 git commit 以及可选的 git push origin master。
当前仓库可能尚未初始化 git。若 git status 报 "not a git repository",先停下来与用户确认是要 git init 并设置远端,还是要先在 GitHub 上创建空仓库后再克隆/绑定 — 不要擅自 git init。
触发条件
只在用户明确要求时调用,例如:
- "帮我提交"、"commit 一下"、"提交这些改动"
- "推送到 GitHub"、"push 到远端"、"上传"
- 显式调用
/commit-push
严禁在用户没有明确要求的情况下自动 commit 或 push——哪怕本轮对话刚改完一堆代码。
提交信息风格(Conventional Commits,英文)
| 类型 | 含义 |
|---|
feat: | 新功能或现有功能的增强 |
fix: | bug 修复 |
chore: | 构建、配置、辅助脚本等非业务改动 |
docs: | 仅文档变动(README、注释除外) |
refactor: | 不改变行为的重构 |
style: | 仅样式 / 排版改动,不影响逻辑 |
init: | 仅初始化提交时使用 |
写作规则:
- 主语全部使用英文(CLAUDE.md 明确:提交信息按英文惯例)。
type: 后跟空格和小写起首的简短描述。
- 多项改动可用逗号合并到一行:
feat: api settings panel, custom provider, model picker。
- 主语短小(≤ 72 字符);如需详述,在空行后写正文。
- 不附加
Co-Authored-By 行 — 与本项目计划保持的无水印风格一致。
仓库尚无历史时,可以参考以下风格起手:
init: scaffold keeper coc trpg with vite + express
feat: api settings panel with multi-provider llm dispatch
chore: dockerize app with multi-stage build
标准流程
1. 提交前侦查(并行执行)
git status # 不要用 -uall
git diff # 已暂存 + 未暂存
git diff --cached # 仅已暂存
git log --pretty=format:"%h %s" -n 5
目标:
- 看清将要进入提交的全部改动。
- 确认风格与最近若干条 commit 一致。
- 发现意外文件(见下方"绝不提交")。
2. 暂存
- 始终按文件名显式
git add <file> <file>,禁止 git add -A / git add . / git add -u。
- 如果用户已经手动
git add 过,直接沿用,不要重复加。
3. 起草提交信息
- 按上节风格起草,先看
git log 确保动词、大小写、用词与近邻提交协调。
- 描述聚焦"为什么"和"带来什么",而不是逐文件罗列"动了什么"。
- 多行信息必须用 HEREDOC 传入,避免 PowerShell/Bash 的引号转义出错:
git commit -m "$(cat <<'EOF'
feat: short subject line
Optional body explaining the why.
EOF
)"
4. 推送(仅在用户要求时)
- 默认目标:
origin master(除非用户指定其它分支)。
- 推送前必须与用户二次确认,特别是包含:构建配置、
Dockerfile、docker-compose.yml、依赖锁文件、大量删除的提交。
- 标准命令:
git push origin master(首次推送可加 -u 设置上游)。
- 推送完成后跑一次
git status 验证本地与远端一致。
绝不提交(pre-check 清单)
如 git status 显示这些文件出现在暂存区或未跟踪区,先停下来询问用户,不要自动加入:
.env、.env.*(已被 .gitignore 排除,例外是 .env.example)
- 任何含 token / API key / 密码字面值的文件
.docs/keeper-*.json 这类玩家私有模组配置(含个人创作内容)
node_modules/、dist/、build/、coverage/、*.log(均已被 .gitignore 排除)
- 大体积二进制(> 5 MB),除非用户确认
- 含 IDE 配置、临时调试代码、个人路径的文件
绝不做的操作
未经用户显式书面同意前:
- ❌
git push --force / --force-with-lease 到 master
- ❌
git commit --amend(尤其是已推送的提交)
- ❌
git reset --hard / git checkout . / git clean -fd
- ❌
git rebase(任何形式)
- ❌
--no-verify、--no-gpg-sign(绕过 hook / 签名)
- ❌ 修改
git config(用户名、邮箱、远端、hooks 等)
- ❌ 删除分支 / 标签
遇到 pre-commit hook 失败,不要用 --amend 修复——先解决 hook 报的问题,重新 git add 后新建一个 commit。
创建 Pull Request(如适用)
本项目当前预期单分支直推;如用户要求改用 PR 流程:
- 新建特性分支:
git checkout -b feat/<short-name>
- 提交、推送:
git push -u origin feat/<short-name>
- 用
gh pr create 创建 PR,标题用 Conventional Commits 风格,body 使用 HEREDOC。
- PR body 不附加 "🤖 Generated with Claude Code" 之类的水印——与本项目无水印风格一致。
给用户的最终汇报
成功 commit / push 后,简短汇报:
- 提交哈希前 7 位和主语
- 是否已推送、本地与远端状态是否一致
- 任何被跳过的文件以及原因