About git-commit
A skill for controlled Git commits, limited to files changed through Write or Edit during the current session. It checks the worktree and branch, reviews diffs, and commits only after the user confirms the file scope and message.
Key features
- 01Limit scope to session-edited files
- 02Check worktree and current branch
- 03Review diffs and identify outside changes
- 04Confirm commit message and branch plan
- 05Stage and commit explicit paths
- 06Verify status and log afterward
Use cases
- 01Commit changes made in the current session
- 02Avoid including files from other work
- 03Create a feature branch before committing on the default branch
- 04Check that a commit landed on the intended branch
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ ouyangjiahong26/ skills --skill git-commitAfter installing, type/git-commitin Claude Code to confirm it loaded.
Bundled filesreferences/git-workflow.md
Details
From the project README只提交本会话改动的文件。改动范围取自本会话的 Write、Edit 调用,git 命令只用来核对与执行。
流程
1. 检查
- 从对话上下文列出本会话修改或新建的仓库文件(会话文件)。
- 运行
git worktree list与git rev-parse --abbrev-ref HEAD,记录当前所在 worktree 与分支。会话文件路径不在当前 cwd 所在 worktree 内(典型:误指向主仓库目录)时,停止并说明:提交将落到错误分支。 - 运行
git status --porcelain列出全部改动(未跟踪、已暂存、未暂存都在内),与会话文件对照:- 改动不在会话文件中的:视为会话外改动,单独列出。
- 会话文件未出现在改动中:实际未改动,剔除并说明。
- 运行
git diff --stat与git diff -- <会话文件>确认每项改动都应提交。新建的未跟踪文件直接读内容确认。 - 确定提交与分支约定:目标仓库有自己的约定(
CONTRIBUTING.md、AGENTS.md、docs/中的提交与分支规则)时,以它为准。仓库没有自己的约定时,用references/git-workflow.md作缺省约定。据此起草 commit message。当前分支是默认分支时,按约定的命名规则确定功能分支名。 - 从对话上下文识别关联 issue(
#N或 issue 链接),在 commit message 中写Fixes #N或Related to #N(按用户意图选)。本 skill 不关闭 Issue、不改 GitHub Project:PR 入板置In review由/open-pr做。合并后置Done并关闭 Issue 由/merge-pr做。
2. 确认并提交
- 展示会话文件、会话外改动、改动摘要、当前分支、拟建的分支名和拟议 commit message。
- 会话外改动存在时,询问是否纳入。默认不纳入。
- 等用户明确确认 message、文件范围和分支名后执行提交。
- 仍在默认分支上时先切出功能分支:
git switch -c <branch>。 - 用明确路径暂存并提交(不用
git add -A/git add .):
git add <file1> <file2> ...
git commit -m "<标题>" -m "<正文>" # 正文可省
3. 验证
运行:
git status -- <会话文件>
git log --oneline -3
git branch --show-current
确认已提交的会话文件不再有未提交改动,且提交落在第 1 步确定的功能分支上,不在默认分支。
边界情况
| 情况 | 处理方式 |
|---|---|
| 会话文件为空 | 不提交,告知用户 |
| 改动含未解决的合并冲突 | 不提交,先解决冲突 |
| diff 与本会话目标不符 | 不提交,说明差异并等待决定 |
| 超过 20 个文件或含多个独立关注点 | 按拆分原则拟分组方案(文件清单与各组 message),等用户确认后逐组提交 |
Comments
Markdown supported