一键导入
ms-git-squash-commits
PR 前将开发分支的多个 commit 压缩成一个,自动同步上游代码并生成 Conventional Commits 风格的提交信息(可选 emoji)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
PR 前将开发分支的多个 commit 压缩成一个,自动同步上游代码并生成 Conventional Commits 风格的提交信息(可选 emoji)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
专门用于 my-claude 项目从上游仓库一键同步更新。自动检测并添加 upstream remote,从 upstream/master 更新到本地 master,合并到当前分支,检查配置变更并提示调整 inventory 配置,最后引导提交和推送。当用户在 my-claude 项目中说"从上游更新"、"同步上游"、"拉取上游代码"等时使用此 skill。
仅用 Git 分析改动并自动生成 conventional commit 信息(可选 emoji);必要时建议拆分提交,默认运行本地 Git 钩子(可 --no-verify 跳过);智能推断是否推送到远程
从上游主分支拉取最新代码,同步到本地主分支,再合并/变基到当前工作分支;遇冲突自动解决
基于 SOC 职业分类
| name | ms-git-squash-commits |
| description | PR 前将开发分支的多个 commit 压缩成一个,自动同步上游代码并生成 Conventional Commits 风格的提交信息(可选 emoji) |
| allowed-tools | Bash(git fetch, git checkout, git merge, git reset, git commit, git branch, git rev-parse, git log, git status, git diff, git remote, git merge-base), Read(**), Write(.git/COMMIT_EDITMSG) |
| argument-hint | [--remote <remote>] [--branch <branch>] [--no-sync] [--backup] [--no-verify] [--emoji] [--scope <scope>] [--type <type>] |
该命令用于在提交 PR 前将开发分支的多个 commit 压缩成一个干净的 commit,通过 Git:
--backup 控制)git reset --soft <upstream-branch>)/ms-git-squash-commits
/ms-git-squash-commits --emoji
/ms-git-squash-commits --scope ui --type feat
/ms-git-squash-commits --no-sync
/ms-git-squash-commits --backup
/ms-git-squash-commits --remote upstream --branch develop
/ms-git-squash-commits --no-verify --emoji
--remote <remote>:指定远程仓库名称(如 upstream、origin)。省略则自动推断(优先 upstream,回退到 origin)。--branch <branch>:指定上游分支名称(如 develop、main、master)。省略则自动推断(优先 develop,回退到 main/master)。--no-sync:仅压缩提交,不同步上游代码(适用于已经同步过的场景)。--backup:在压缩前创建备份分支(命名为 <当前分支>-backup-<时间戳>)。--no-verify:跳过本地 Git 钩子(pre-commit/commit-msg 等)。--emoji:在提交信息中包含 emoji 前缀(省略则使用纯文本)。--scope <scope>:指定提交作用域(如 ui、docs、api),写入消息头部。--type <type>:强制提交类型(如 feat、fix、docs 等),覆盖自动判断。注:如框架不支持交互式确认,可在 front-matter 中开启
confirm: true以避免误操作。
仓库/分支校验
git rev-parse --is-inside-work-tree 判断是否位于 Git 仓库。git status --porcelain),若有未提交改动,提示用户先提交或暂存。上游分支检测与验证
--remote → 使用指定 remote。upstream > origin(优先 upstream,若不存在则使用 origin)。--branch → 使用指定 branch。develop > main > master(检查远程分支是否存在)。git rev-parse --verify <remote>/<branch> 验证分支存在性。上游代码同步(可选)
--no-sync:跳过此步骤,直接进入压缩流程。git fetch <remote> 拉取最新代码。git merge <remote>/<branch> 合并到当前分支。若产生冲突,尝试自动解决(基于语义分析)。
若自动解决失败,报告冲突文件并给出建议命令:
# 手动解决冲突后执行:
git add <冲突文件>
git commit -m "resolve merge conflicts"
# 然后重新运行此命令
退出命令,等待用户手动处理。
备份当前分支(可选)
--backup:
git branch <当前分支>-backup-<时间戳>。统计要压缩的提交
执行 git log --oneline <remote>/<branch>..HEAD 统计提交数量。
若提交数量为 0,提示用户当前分支没有新提交,退出命令。
若提交数量为 1,询问用户是否继续(已经是单个提交,可能不需要压缩)。
输出提交列表供用户确认:
检测到 5 个提交需要压缩:
- abc1234 feat: add feature A
- def5678 fix: typo in feature A
- ghi9012 refactor: extract helper function
- jkl3456 docs: update API docs
- mno7890 chore: format code
执行软重置(压缩提交)
git reset --soft <remote>/<branch>。--soft 参数只移动 HEAD 指针,不改变暂存区和工作区。生成压缩后的提交信息
git diff --cached)。--type/--scope → 使用指定值。scope(如 src/ui/ → ui)。type(如新增功能 → feat,修复 bug → fix)。[<emoji>] <type>(<scope>)?: <subject>(首行 ≤ 72 字符,祈使语气,仅在使用 --emoji 时包含 emoji)。.git/COMMIT_EDITMSG。创建新的压缩提交
git commit [--no-verify] -F .git/COMMIT_EDITMSG。验证与对比
执行 git log --oneline --graph -5 显示最近提交历史。
对比压缩前后的提交数量:
压缩完成!
- 原提交数量:5
- 压缩后提交数量:1
- 压缩提交 hash:abc1234
- 压缩提交标题:feat(ui): implement user authentication flow
若创建了备份分支,提醒用户:
备份分支已创建:feat-dev-backup-20260226-143022
若需要恢复,请执行:git reset --hard feat-dev-backup-20260226-143022
--backup,以防万一操作失误。--no-sync),避免后续 PR 合并时产生冲突。feat:新增功能fix:缺陷修复(含 🔥 删除代码/文件、🚑️ 紧急修复、👽️ 适配外部 API 变更、🔒️ 安全修复、🚨 解决告警、💚 修复 CI)docs:文档与注释style:风格/格式(不改语义)refactor:重构(不新增功能、不修缺陷)perf:性能优化test:新增/修复测试、快照chore:构建/工具/杂务(合并分支、更新配置、发布标记、依赖 pin、.gitignore 等)ci:CI/CD 配置与脚本revert:回滚提交feat:破坏性变更(BREAKING CHANGE: 段落中说明)若传入
--type/--scope,将覆盖自动推断。 仅在指定--emoji标志时才会包含 emoji。
feat(ui): implement user authentication flow
实现用户认证流程,包括登录、注册、密码重置功能。
原始提交历史:
- abc1234 feat: add login form component
- def5678 fix: typo in login validation
- ghi9012 refactor: extract validation logic
- jkl3456 docs: add API documentation
- mno7890 chore: format code
主要改动:
- 新增 LoginForm、RegisterForm 组件
- 实现 JWT token 验证逻辑
- 添加密码强度检查
- 更新 API 文档
影响范围:
- src/components/auth/
- src/services/auth-service.ts
- docs/api/authentication.md
pnpm/npm/yarn 等)。--no-verify 可跳过。.git/COMMIT_EDITMSG 与暂存区;不会直接编辑工作区文件。--backup,以防万一操作失误。<当前分支>-backup-<时间戳>。git reset --hard <备份分支>。--no-sync),避免后续 PR 合并时产生冲突。--no-sync 跳过同步步骤。confirm: true,每个实际 git reset/git commit 步骤都会进行二次确认。