一键导入
extract-pr
Extracts a specific subset of branch changes into a clean pull request without unrelated changes.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Extracts a specific subset of branch changes into a clean pull request without unrelated changes.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Merges completed work back to main through a protected-branch pull request workflow.
Set up a new git worktree and install dependencies.
Merges completed work back to main through a protected-branch pull request workflow.
Set up a new git worktree and install dependencies.
Prepares a Python package for PyPI release by updating the version, building, and verifying the distribution.
Prepare a release by updating the version, building, and verifying the distribution.
| name | extract-pr |
| description | Extracts a specific subset of branch changes into a clean pull request without unrelated changes. |
Extract a specific subset of changes from a branch into a clean PR, without introducing anything beyond what's needed for that subset.
$ARGUMENTS
Ask the user:
Review all commits on the branch:
git log --oneline main..HEAD
For each commit that might be part of the subset, examine it:
git show <commit-hash> --stat
git show <commit-hash>
Decision Point: Does the subset map cleanly to one or more complete commits?
After examining the commits, present your analysis to the user and ask which path to take:
Wait for user confirmation before proceeding to either path.
Important: Cherry-pick works fine for sequential commits even if later ones depend on earlier ones - just cherry-pick them in order. Don't confuse "commits build on each other" with "commits are intertwined with unrelated changes". Path A is valid as long as each commit contains ONLY subset changes, regardless of whether commits depend on each other.
Use this path when specific commits contain ONLY the changes needed for the subset.
git reset --hard main
git cherry-pick <commit1> <commit2> ...
Note: This is the same as Step B7 - both paths converge here.
git diff main --name-only
git diff main --stat
Review the list of changed files and confirm they belong in this subset. Use git diff main -- <file> to inspect as many specific files as needed—apply judgment about which files warrant detailed review vs. which are obvious (e.g., large generated artifacts). If any unrelated changes are present, identify what needs to be fixed before proceeding.
Note: This is the same as Step B8 - both paths converge here.
poetry run pytest
poetry run ruff check .
poetry run pyright
Verify all tests and checks pass. If any fail, fix them before proceeding.
Use this path when commits are intertwined with unrelated changes.
git diff main --name-status
Categorize each changed file:
git checkout main -- <file> if unrelatedFor each file, determine if it belongs in the target subset:
For files that exist on main and should be reverted:
git checkout main -- <file1> <file2> ...
For new files that should be removed:
rm -f <new-file1> <new-file2> ...
rm -rf <new-directory>/
For files that ARE part of the subset but contain unrelated changes mixed in:
git show main:<file>If the subset is a reorganization (moving/restructuring existing information—code, documentation, configuration, etc.):
git show main:<original-file> should contain the same information now in the new locationKey insight: A "new" file in a reorganization PR should only contain information extracted from existing files on main. If it has information that doesn't exist on main, that's new—not reorganization.
When moving content, links and references often need updating:
Note: This is the same as Step A2 - both paths converge here.
git diff main --name-only
git diff main --stat
Review the list of changed files and confirm they belong in this subset. Use git diff main -- <file> to inspect as many specific files as needed—apply judgment about which files warrant detailed review vs. which are obvious (e.g., large generated artifacts). If any unrelated changes are present, identify what needs to be fixed before proceeding.
Note: This is the same as Step A3 - both paths converge here.
poetry run pytest
poetry run ruff check .
poetry run pyright
Verify all tests and checks pass. If any fail, fix them before proceeding.
Stage all changes and create a single commit:
git add -A
git commit -m "<descriptive message>"
If there are existing commits to squash:
git reset --soft main # Keep changes staged, remove commits
git commit -m "<message>" # Single clean commit
After extraction is complete and tests pass, run /finish to merge main, run CI checks, and create the PR. Do NOT manually create a PR with gh pr create - always use /finish which handles the full workflow including merging latest main and proper PR creation.
git reset --soft main to collapse messy history into a single commit while preserving the final state.Keeping unrelated changes that happen to touch the same files: A file might be modified for multiple reasons. Extract only the changes relevant to the subset.
For reorganization: keeping "moved" information that's actually new: A new file might look like it's part of a reorganization but actually contains new information. Verify all information traces back to main.
Forgetting to remove new directories: git checkout doesn't remove directories that don't exist on main. Use rm -rf for new directories.
Assuming what belongs in vs. out: When content could reasonably go either way (e.g., generic guidelines developed alongside a feature), ask the user to clarify the extraction boundaries. The goal is to slim down the source PR—don't leave things behind just because "they'll get merged eventually." Think purely about what lightens the source PR vs. what must stay with it.
Partial staging before soft reset: When collapsing history with git reset --soft main, ensure ALL your working directory changes are included. If you have both staged changes (from previous commits) and unstaged changes (from reverts/edits), you must git add -A after the reset to capture everything. The soft reset preserves staged changes from commits, but your manual reverts may be unstaged.
Undoing your own reverts with cleanup commands: After git checkout main -- <files> successfully reverts files, DO NOT run git checkout -- . (restores from HEAD, undoing your reverts), git reset HEAD (unstages your changes), or git clean -fd (removes files you may need). These commands undo your extraction work. If git status shows staged files after reverting, that's expected—proceed to git add -A and commit. Don't panic and "clean up" the staging area.