关于 stacked-prs
介绍如何规划和管理彼此依赖、逐层构建的 Pull Request,涵盖分支顺序、审查与变基,并建议仅在明确提出或任务阶段存在依赖时采用堆叠 PR。
主要功能
- 01按顺序命名分支
- 02从前序分支创建后续分支
- 03记录 PR 依赖关系
- 04安全变基依赖分支
- 05合并策略指南
适用场景
- 01将大型功能拆分为依赖式审查
- 02基础 PR 收到反馈后更新堆栈
- 03为分阶段实现规划分支
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ bobmatnyc/ claude-mpm-skills --skill stacked-prs安装后在 Claude Code 中输入/stacked-prs确认已加载。
附带文件metadata.json
详细介绍
堆叠式拉取请求
概述
堆叠式 PR 是彼此依赖的拉取请求,每个 PR 都建立在前一个 PR 的基础上。对于需要逻辑拆分并行评审的复杂功能,可以使用这种模式。
适用场景
✅ 适合使用堆叠式 PR 的场景:
- 用户明确要求使用“堆叠式 PR”或“依赖型 PR”
- 大型功能需要拆分为逻辑阶段
- 每个阶段都明确依赖前一阶段
- 用户熟悉 rebase 工作流
❌ 适合使用基于 main 的 PR 的场景(默认):
- 功能彼此独立
- 简单的 bug 修复或增强
- 多个 Agent 并行工作
- 用户未指定偏好
默认:除非用户明确要求堆叠,否则始终优先使用基于 main 的 PR。
分支命名约定
使用连续编号来表示依赖关系:
feature/001-base-authentication # PR-001 (base)
feature/002-user-profile # PR-002 (depends on 001)
feature/003-admin-panel # PR-003 (depends on 002)
其他命名模式:
auth/01-foundation
auth/02-user-flow
auth/03-admin-features
创建堆叠式 PR
步骤 1:创建基础 PR(PR-001)
# Start from main
git checkout main
git pull origin main
# Create base branch
git checkout -b feature/001-base-auth
# Implement base functionality
# ... work ...
# Push and create PR
git push -u origin feature/001-base-auth
# Create PR in GitHub/GitLab
# Title: "[1/3] Base authentication foundation"
# Base: main
# Description: Include stack overview (see template below)
步骤 2:创建依赖 PR(PR-002)
重要:基于前一个功能分支,而不是 main
# Start from PR-001's branch
git checkout feature/001-base-auth
git pull origin feature/001-base-auth
# Create dependent branch
git checkout -b feature/002-user-profile
# Implement dependent functionality
# ... work ...
# Push and create PR
git push -u origin feature/002-user-profile
# Create PR in GitHub/GitLab
# Title: "[2/3] User profile management"
# Base: feature/001-base-auth ← NOT main!
# Description: "Depends on PR #123"
步骤 3:创建最终 PR(PR-003)
# Start from PR-002's branch
git checkout feature/002-user-profile
git pull origin feature/002-user-profile
# Create final branch
git checkout -b feature/003-admin-panel
# Implement final functionality
# ... work ...
# Push and create PR
git push -u origin feature/003-admin-panel
# Create PR in GitHub/GitLab
# Title: "[3/3] Admin panel with full auth"
# Base: feature/002-user-profile ← NOT main!
# Description: "Depends on PR #124"
PR 描述模板
堆叠式 PR 请使用此模板:
## This PR
[Brief description of changes in THIS PR only]
## Depends On
- PR #123 (feature/001-base-auth) - Must merge first
- Builds on top of authentication foundation
## Stack Overview
1. PR #123: Base authentication (feature/001-base-auth) ← MERGE FIRST
2. PR #124: User profile (feature/002-user-profile) ← THIS PR
3. PR #125: Admin panel (feature/003-admin-panel) - Coming next
## Review Guidance
To see ONLY this PR's changes:
```bash
git diff feature/001-base-auth...feature/002-user-profile
也可以在 GitHub 上比较:feature/002-user-profile...feature/001-base-auth(三个点)
测试
- 已与 PR #123 组合测试
- 包含用户资料功能的测试
- 与基础身份验证层集成的测试通过
## Managing Rebase Chains
### When Base PR Changes (Review Feedback)
If PR-001 gets updated, rebase dependent PRs:
```bash
# Update PR-001 (base)
git checkout feature/001-base-auth
git pull origin feature/001-base-auth
# Rebase PR-002 on updated base
git checkout feature/002-user-profile
git rebase feature/001-base-auth
git push --force-with-lease origin feature/002-user-profile
# Rebase PR-003 on updated PR-002
git checkout feature/003-admin-panel
git rebase feature/002-user-profile
git push --force-with-lease origin feature/003-admin-panel
重要:为确保安全,请使用 --force-with-lease,不要使用 --force
合并策略
方案 A:按顺序合并(推荐)
- 将 PR-001 合并到 main
- 将 PR-002 的目标分支改为 main(在 GitHub 上:点击 PR 上的“Edit”按钮)
- 将 PR-002 合并到 main
- 将 PR-003 的目标分支改为 main
- 将 PR-003 合并到 main
方案 B:保留堆叠直到最后
- 将 PR-001 合并到 main
- 在 PR-001 完全合并之前,保持 PR-002 基于 feature/001
- 然后将 PR-002 rebase 到 main 上
- 对 PR-003 重复上述步骤
常见误区
❌ 错误:所有 PR 都基于 main
git checkout main
git checkout -b feature/001-base
# PR: feature/001-base → main
git checkout main # ← WRONG
git checkout -b feature/002-next
# PR: feature/002-next → main # ← WRONG (independent, not stacked)
✅ 正确:每个 PR 都基于前一个 PR
git checkout main
git checkout -b feature/001-base
# PR: feature/001-base → main
git checkout feature/001-base # ← CORRECT
git checkout -b feature/002-next
# PR: feature/002-next → feature/001-base # ← CORRECT (stacked)
Agent 指引
将创建堆叠式 PR 的工作委派给版本控制 Agent 时:
Task: Create stacked PR branch structure
Stack Sequence:
1. PR-001: feature/001-base-auth → main (base layer)
2. PR-002: feature/002-user-profile → feature/001-base-auth (depends on 001)
3. PR-003: feature/003-admin-panel → feature/002-user-profile (depends on 002)
Requirements:
- Each branch MUST be based on previous feature branch
- Use sequential numbering (001, 002, 003)
- Include "depends on" notes in commit messages
- Create PR description with stack overview
CRITICAL: PR-002 bases on feature/001-base-auth, NOT on main
CRITICAL: PR-003 bases on feature/002-user-profile, NOT on main
验证清单
创建堆叠式 PR 前:
- 用户明确要求使用堆叠式 PR
- 功能有明确的逻辑阶段
- 每个阶段都依赖前一阶段
- 用户了解 rebase 工作流
- 分支名称使用连续编号
- 每个分支都基于正确的分支(前一个功能分支)创建
- PR 描述包含依赖关系信息
- 每个 PR 都记录了堆叠概述
相关技能
git-worktrees- 同时处理多个 PRgit-workflow- 通用 Git 分支模式code-review- 堆叠式 PR 的评审策略
评论
支持 Markdown