SuperAPI AI 工具集

gh-stack

通用与其它

查看项目

更新于 10-16 03:44

技能介绍

用途:gh-stack 是 gh 的扩展,用于管理堆叠式分支与依赖型 PR。一个 stack 是以仓库远端默认分支为根的线性依赖链,每个分支对应一个 PR,其 base 是下方分支。整个生命周期都应使用 gh stack 命令,普通 push、PR 创建和 PR 合并不会保留堆叠状态。

主要能力:初始化与扩展堆叠(gh stack init、gh stack add)、提交(gh stack submit --auto)、查看(gh stack view --json)、切换(gh stack checkout)、向上重基(gh stack rebase --upstack)、合并后同步(gh stack sync)、合并(gh stack merge --yes --squash)。

使用方式:所有命令非交互执行,显式传入分支、PR、stack、remote 和模式参数。先检查远端与默认分支:git remote -v、git branch --show-current、git symbolic-ref --short refs/remotes/origin/HEAD、gh stack view --json。提交示例:git add <exact paths>;git commit -m "type(scope): coherent invariant";gh stack submit --auto --remote origin。修改下层分支后执行 gh stack rebase --upstack --remote origin 再提交。合并用 gh stack merge <stack-or-pr-number> --yes --squash,不要用 gh pr merge。

适用场景:需要把多个相互依赖的 PR 组织成链式审查与合并时。

限制与注意:不要跨 stack 共享分支;不要为恢复 stack 破坏或重写用户工作;冲突需明确解决或中止。退出码 2 表示当前检出不在 stack 中,3 为 rebase 冲突,6 为分支属于多个 stack,7 为已有 rebase 未完成,8 为 stack 锁被占用。不熟悉的破坏性操作前应运行 gh stack <command> --help,以已安装 CLI 为准。认证、API 或仓库功能失败需修复前置条件,不要退回普通 GitHub PR 命令。