gh-stackx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

gh-stackx

gh-stackx

Use the
gh-stackx
gh
extension to manage stacked pull requests on repositories that do not have the private-preview GitHub Stacked PRs API.
使用
gh-stackx
这个
gh
扩展,在不支持GitHub Stacked PRs API私有预览版的仓库上管理stacked pull requests

When to use

使用场景

  • You want to open a series of dependent PRs.
  • gh stack submit
    fails with
    ⚠ Stacked PRs are not enabled for this repository
    .
  • You need to keep PR bases correct as the stack is rebased or merged.
  • You want to merge a stack from the top down without manually editing PR bases.
  • 你需要创建一系列相互依赖的PR。
  • gh stack submit
    执行失败并提示
    ⚠ Stacked PRs are not enabled for this repository
  • 当堆叠分支被变基或合并时,你需要保持PR的基准分支正确。
  • 你希望从上到下合并整个堆叠分支,而无需手动编辑PR的基准分支。

Prerequisites

前置条件

  • gh
    CLI installed and authenticated.
  • github/gh-stack
    extension installed for local stack operations:
    bash
    gh extension install github/gh-stack
  • gh-stackx
    installed:
    bash
    gh extension install ThePlenkov/gh-stackx
  • 已安装并完成认证的
    gh
    CLI。
  • 已安装用于本地堆叠操作的
    github/gh-stack
    扩展:
    bash
    gh extension install github/gh-stack
  • 已安装
    gh-stackx
    bash
    gh extension install ThePlenkov/gh-stackx

Core concepts

核心概念

  • Trunk — the base branch, usually
    main
    .
  • Stack — an ordered list of branches where each branch builds on the previous one.
  • Bottom — the branch closest to trunk.
  • Top — the branch farthest from trunk.
  • Base — the parent branch for a PR. The bottom layer uses trunk; every other layer uses the previous branch.
  • Trunk — 基准分支,通常为
    main
  • Stack — 有序的分支列表,每个分支都基于前一个分支构建。
  • Bottom — 最接近Trunk的分支。
  • Top — 离Trunk最远的分支。
  • Base — PR的父分支。最底层分支使用Trunk;其他所有层都使用前一个分支作为基准。

Workflow

工作流程

Create a stack

创建堆叠分支

bash
git checkout main
git pull origin main

gh stackx init feature/auth
bash
git checkout main
git pull origin main

gh stackx init feature/auth

work and commit

进行开发并提交

gh stackx add feature/api
gh stackx add feature/api

work and commit

进行开发并提交

gh stackx add feature/ui
gh stackx add feature/ui

work and commit

进行开发并提交

undefined
undefined

Submit PRs

提交PR

bash
gh stackx submit       # drafts
gh stackx submit --open
submit
pushes all branches and creates/updates PRs bottom-up with the correct
--base
and
--head
.
bash
gh stackx submit       # 草稿状态
gh stackx submit --open
submit
命令会推送所有分支,并从下到上创建/更新PR,设置正确的
--base
--head
参数。

Sync after trunk or parent PR changes

主干或父PR变更后同步

bash
gh stackx sync
gh stackx sync --remote upstream
sync
runs
gh stack sync
and then updates every open PR base with
gh pr edit --base
.
bash
gh stackx sync
gh stackx sync --remote upstream
sync
命令会先执行
gh stack sync
,然后通过
gh pr edit --base
更新所有已打开PR的基准分支。

Merge top-down

从上到下合并

bash
gh stackx merge
gh stackx merge --squash
gh stackx merge --rebase
merge
starts at the top of the stack and merges each open PR with
gh pr merge
.
bash
gh stackx merge
gh stackx merge --squash
gh stackx merge --rebase
merge
命令从堆叠分支的顶部开始,使用
gh pr merge
合并每个已打开的PR。

Local navigation

本地导航

These pass through to
github/gh-stack
:
bash
gh stackx view --json
gh stackx up
gh stackx down
gh stackx top
gh stackx bottom
gh stackx trunk
以下命令会直接调用
github/gh-stack
bash
gh stackx view --json
gh stackx up
gh stackx down
gh stackx top
gh stackx bottom
gh stackx trunk

Important rules

重要规则

  • Keep the working tree clean before
    sync
    or
    merge
    ; rebase operations fail on uncommitted changes.
  • Create PRs bottom-up so each base exists before the child PR is opened.
  • Merge top-down so dependent PRs are merged before their parents move.
  • Do not commit
    .git/gh-stack
    . It is local metadata.
  • 在执行
    sync
    merge
    前保持工作树干净;未提交的变更会导致变基操作失败。
  • 从下到上创建PR,确保每个子PR打开前其基准分支已存在。
  • 从上到下合并PR,确保依赖PR在其父分支合并前完成合并。
  • 不要提交
    .git/gh-stack
    文件,它是本地元数据。

Troubleshooting

故障排查

  • gh stackx view
    fails: ensure
    github/gh-stack
    is installed.
  • A PR has the wrong base: run
    gh stackx sync
    .
  • submit
    or
    merge
    stops with errors: fix the underlying
    gh pr
    issue, then re-run.
  • gh stackx view
    执行失败:确保已安装
    github/gh-stack
    扩展。
  • PR的基准分支错误:执行
    gh stackx sync
  • submit
    merge
    命令因错误停止:修复底层的
    gh pr
    问题,然后重新执行命令。

Install this skill

安装该Skill

With
npx skills
(Vercel skills):
bash
npx skills add ThePlenkov/gh-stackx --skill gh-stackx
With
npx skill
(CodeBuddy):
bash
SKILL_BASE_URL=https://github.com/ThePlenkov/gh-stackx/tree/main npx skill skills/gh-stackx
使用
npx skills
(Vercel skills):
bash
npx skills add ThePlenkov/gh-stackx --skill gh-stackx
使用
npx skill
(CodeBuddy):
bash
SKILL_BASE_URL=https://github.com/ThePlenkov/gh-stackx/tree/main npx skill skills/gh-stackx

Further reading

更多阅读

The full workflow is already inline above. For more, see the repository:
完整工作流程已在上方列出。如需更多内容,请查看仓库: