mcpField
C
commit-push

commit-push

github.com/existential-birds开发8564 次安装11 周前更新
代码仓库

关于 commit-push

commit-push 是用于按 Conventional Commits 格式提交本地更改并推送到远程端的技能。它通过逐步检查确认差异、暂存文件、目标分支与远程端,以及推送后的状态。

主要功能

  1. 01检查工作区状态与差异
  2. 02拟定 Conventional Commits 消息
  3. 03提交前核对暂存文件
  4. 04推送前确认分支与远程端
  5. 05推送后检查工作区和同步状态

适用场景

  1. 01提交已审查的一组本地更改
  2. 02将更改推送到指定分支和远程端
  3. 03推送后确认仓库已同步

安装

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

$npx skills add https://github.com/existential-birds/beagle --skill commit-push

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

详细介绍

提交并推送

按照 Conventional Commits 格式提交所有本地更改并推送到远程。

检查关卡

按顺序完成。只有满足通过条件后,才能执行下一项操作(以命令输出为依据,不要凭记忆判断)。

  1. 已理解差异 — 通过条件: git status、git diff 和 git diff --cached 的输出与你对更改内容的一句话描述一致(或者你已记录没有需要提交的内容)。
  2. 已选定提交行 — 通过条件: 你已拟好首行 type(scope): description(如果省略 scope,则为 type: description),且与计划发布的更改集相符。
  3. 暂存内容符合预期 — 通过条件: 执行 git add 后,git diff --cached --stat(必要时抽查 git diff --cached)仅显示你计划纳入的路径;如果不符,请在提交前调整暂存内容。
  4. 已确认推送目标 — 通过条件: 当前分支和远程仓库均为预期目标(通过 git branch -vv、git remote -v 确认);然后再推送。
  5. 远程已同步 — 通过条件: git status 显示工作区干净,且 git status -sb 显示分支已与配置的上游分支同步(此任务没有意外的未推送提交)。

第 1 步:收集上下文

并行运行以下命令以了解更改:

# See all untracked and modified files
git status

# See staged and unstaged changes
git diff
git diff --cached

# See recent commit messages for style reference
git log --oneline -10

第 2 步:分析更改

审查更改并确定:

  • 类型:这属于哪种更改?

    • feat - 新功能或能力
    • fix - Bug 修复
    • docs - 仅文档更改
    • refactor - 重构代码,不改变行为
    • test - 添加或更新测试
    • chore - 维护、依赖项更新
    • perf - 性能改进
    • ci - CI/CD 更改
  • 范围:影响哪个组件?

    • 检查更改的文件并确定合适的范围
    • 在项目中使用一致的范围名称(通过 git log 查看命名惯例)
    • (跨领域更改可省略范围)
  • 破坏性更改:是否会破坏向后兼容性?如果是,请在 scope 后添加 !。

第 3 步:编写提交消息

格式:

type(scope): description

[optional body explaining why, not what]

[optional footer with issue references]

规则:

  • 使用祈使语气:“add feature”,而不是 “added feature”
  • 首行保持在 72 个字符以内
  • 正文说明原因,差异内容已展示更改了什么
  • 引用议题:Closes #123 或 Fixes #456

第 4 步:暂存、提交并推送

执行 git commit 前满足检查关卡 1–3;执行 git push 前满足检查关卡 4;推送后满足检查关卡 5。

# Stage all changes (or selectively stage)
git add -A

# Gate 3: confirm staged set before committing
git diff --cached --stat

# Commit with message (use HEREDOC for multi-line)
git commit -m "$(cat <<'EOF'
type(scope): description

Optional body explaining the motivation.

Closes #123
EOF
)"

# Push to remote
git push

示例

# Simple feature
git commit -m "feat(api): add pagination support to list endpoints"

# Bug fix with body
git commit -m "$(cat <<'EOF'
fix(auth): handle token expiration during long requests

The previous implementation did not account for tokens expiring
during the processing of long-running requests.

Fixes #42
EOF
)"

# Breaking change
git commit -m "$(cat <<'EOF'
feat!(api): change response format for user endpoints

BREAKING CHANGE: The `status` field is now an object with `state` and
`message` properties instead of a plain string.
EOF
)"

根据项目惯例,可以选择附加共同作者或页脚尾注(例如 Co-Authored-By: 行或工具归属页脚)。如果项目没有这类惯例,则省略。

第 5 步:验证

推送后满足检查关卡 5:运行 git status 和 git status -sb,确认工作区干净且与上游同步(或者存在可解释的预期 ahead/behind 状态,例如 fork 工作流)。

评论

支持 Markdown