stack
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStack
Stack
Use the local CLI for squash-safe stacked PR repair. It is designed for
repos where PRs are squash-merged and merged branches are deleted, so Git ancestry
alone cannot preserve stack intent.
stackKeep ordinary editing and commits on plain . Use only for stack
intent, stack inspection, sync, merge, and undo workflows.
gitstack使用本地 CLI 进行 squash-safe 的堆叠PR修复。它专为采用 squash-merge 方式合并PR、且合并后分支会被删除的仓库设计,因此仅靠Git祖先记录无法保留堆叠意图。
stack日常编辑和提交使用普通的 即可。仅在处理堆叠意图、堆叠检查、同步、合并和撤销工作流时使用 。
gitstackMental Model
心智模型
text
dev
└─ stack-a #101
└─ stack-b #102
└─ stack-c #103Stack intent is persisted in as stack links:
.git/stack/state.json- branch
- parent branch
- merge-base anchor
- PR number
Mutating sync and merge workflows write so
can restore the previous branch tips, PR bases, and stack metadata.
.git/stack/undo.jsonstack undo --applytext
dev
└─ stack-a #101
└─ stack-b #102
└─ stack-c #103堆叠意图以堆叠链接的形式保存在 文件中,包含以下信息:
.git/stack/state.json- 分支
- 父分支
- 合并基准锚点
- PR编号
修改类的同步和合并工作流会写入 ,因此可通过 恢复之前的分支尖端、PR基准和堆叠元数据。
.git/stack/undo.jsonstack undo --applyCommon Commands
常用命令
- : show the relevant tracked stack graph and include open PR details when GitHub is available.
stack status - : print the opinionated happy path for agents and humans.
stack guide - : record stack intent for an existing branch.
stack track <branch> --onto <parent> - : preview inferred PR-base stack links and repairs without changing branches or PRs.
stack sync --dry-run [branch] - : infer clear PR-base stack links, repair descendants, retarget PRs, and refresh stack blocks. With a branch argument, sync only the stack containing that branch.
stack sync [branch] - /
stack sync --continue-on-failure: process independent stacks, summarize successes and failures, and exit nonzero if any stack failed.stack sync --keep-going - : inspect local Git, GitHub, stack metadata, trunk branches, and undo journal health without changing anything.
stack doctor - : dry-run root PR merge plus descendant repair.
stack merge [branch] - : retarget immediate child PRs, squash-merge the root PR, then repair descendants.
stack merge [branch] --apply - : retarget immediate child PRs, enable GitHub auto-merge, wait, then repair descendants.
stack merge [branch] --auto - : repeat auto-merge one root at a time until the target branch or PR lands.
stack merge --auto --through <branch-or-pr> - : show the most recent applied repair journal.
stack history - : dry-run restore of the most recent applied repair.
stack undo - : restore branches, PR bases, and stack metadata from the journal.
stack undo --apply
- :显示相关的已跟踪堆叠图,当可连接GitHub时,会包含未关闭PR的详细信息。
stack status - :打印面向Agent和人类的标准化操作路径。
stack guide - :为现有分支记录堆叠意图。
stack track <branch> --onto <parent> - :预览推断出的PR基准堆叠链接和修复操作,不会修改分支或PR。
stack sync --dry-run [branch] - :推断明确的PR基准堆叠链接,修复子分支,重新定位PR,并刷新堆叠块。若指定分支参数,则仅同步包含该分支的堆叠。
stack sync [branch] - /
stack sync --continue-on-failure:处理独立堆叠,汇总成功和失败情况,若有堆叠处理失败则返回非零退出码。stack sync --keep-going - :检查本地Git、GitHub、堆叠元数据、主干分支和撤销日志的健康状态,不会进行任何修改。
stack doctor - :预演根PR合并及子分支修复操作。
stack merge [branch] - :重新定位直接子PR,squash-merge根PR,然后修复子分支。
stack merge [branch] --apply - :重新定位直接子PR,启用GitHub自动合并,等待合并完成后自动修复子分支。
stack merge [branch] --auto - :逐个自动合并根PR,直到目标分支或PR合并完成。
stack merge --auto --through <branch-or-pr> - :显示最近应用的修复日志。
stack history - :预演恢复最近一次应用的修复操作。
stack undo - :从日志中恢复分支、PR基准和堆叠元数据。
stack undo --apply
Happy Path: PR Bases Encode The Stack
理想工作流:PR基准定义堆叠
bash
gh pr create --base dev --head stack-a
gh pr create --base stack-a --head stack-b
stack sync --dry-run
stack sync
stack sync cleanup/schema-source
stack sync --keep-goingPrefer this workflow. should show the inferred links, and
records them, removes stale local links, repairs descendants if
needed, retargets PRs, and refreshes stack blocks.
stack sync --dry-runstack syncUse when you need the CLI itself to print this guidance.
stack guidebash
gh pr create --base dev --head stack-a
gh pr create --base stack-a --head stack-b
stack sync --dry-run
stack sync
stack sync cleanup/schema-source
stack sync --keep-going优先采用此工作流。 应显示推断出的链接, 会记录这些链接、移除过时的本地链接、必要时修复子分支、重新定位PR,并刷新堆叠块。
stack sync --dry-runstack sync当需要CLI自行打印此操作指南时,使用 。
stack guideInspect A Stack
检查堆叠
bash
stack statusUse this to understand local stack metadata, current branch position, missing
parents, tracked PR numbers, and PR titles when GitHub is available. It is
opinionated: backup branches are hidden, and when the current branch is
stack-relevant it focuses on that stack instead of listing every local branch.
Use , not , when you need GitHub PR-base
inference before mutation.
stack sync --dry-runstack statusbash
stack status使用此命令了解本地堆叠元数据、当前分支位置、缺失的父分支、已跟踪的PR编号,以及当可连接GitHub时的PR标题。该命令具有倾向性:会隐藏备份分支,且当当前分支与堆叠相关时,会聚焦于该堆叠而非列出所有本地分支。
当需要在修改前通过GitHub PR基准进行推断时,请使用 ,而非 。
stack sync --dry-runstack statusTrack Existing Branches
跟踪现有分支
bash
stack track stack-b --onto stack-a
stack track stack-c --onto stack-bThis records stack intent without changing commits or PRs. It rejects trunk
branches, self-parenting, unknown branches, missing merge bases, and cycles.
bash
stack track stack-b --onto stack-a
stack track stack-c --onto stack-b此命令会记录堆叠意图,但不会修改提交或PR。它会拒绝主干分支、自关联父分支、未知分支、缺失合并基准的分支以及循环分支。
Sync The Common Safe Workflow
同步通用安全工作流
bash
stack sync --dry-run
stack syncUse when open PR bases already describe the stack, a parent PR branch has
changed, or the repo needs the safe common maintenance flow. It:
sync- infers clear PR-base stack links
- removes stale local stack links when no open PR depends on them
- updates stale explicit links when open PR bases clearly show the current stack
- skips standalone trunk-root PRs unless another open PR is based on them
- repairs descendants after squash merges or parent drift
- retargets PR bases
- refreshes stack blocks in PR bodies
- prints a concise tree summary of changed, planned, or failed branches
Run first when you want a preview of inferred links and
repairs before mutation.
stack sync --dry-runstack sync <branch>stack sync--dry-runUse or when one
independent stack should not block the rest. It runs each root stack separately,
prints succeeded and failed stacks, preserves the usual failure cleanup block for
each failed stack, saves undo information for every mutated stack, and exits
nonzero if any stack failed.
stack sync --continue-on-failurestack sync --keep-goingSync output is intentionally outcome-oriented. It should show the stack tree with
icons like , , , and , plus changed PRs/backups/undo instructions. It
should not default to internal phase logs like fetch, inspect, or reconcile.
●✓◌✕If a replay fails, aborts the failed cherry-pick, restores the
original branch, deletes the temporary replay branch, keeps backups and the undo
journal, and tells the user which branch to repair before running
again.
stack syncstack syncDo not edit by hand. If local metadata is stale, run
; if the preview is correct, run .
.git/stack/state.jsonstack sync --dry-runstack syncbash
stack sync --dry-run
stack sync当未关闭PR的基准已描述堆叠、父PR分支已更改,或仓库需要安全的通用维护流程时,使用 命令。它会:
sync- 推断明确的PR基准堆叠链接
- 当没有未关闭PR依赖过时的本地堆叠链接时,将其移除
- 当未关闭PR基准明确显示当前堆叠时,更新过时的显式链接
- 跳过独立的主干根PR,除非有其他未关闭PR基于它
- 在squash合并或父分支偏移后修复子分支
- 重新定位PR基准
- 刷新PR正文中的堆叠块
- 打印简洁的树状摘要,展示已更改、计划更改或处理失败的分支
当需要在修改前预览推断出的链接和修复操作时,请先运行 。
stack sync --dry-runstack sync <branch>stack sync--dry-run当一个独立堆叠不应阻塞其他堆叠时,使用 或 。它会分别运行每个根堆叠,打印成功和失败的堆叠,为每个失败的堆叠保留常规的失败清理块,为每个已修改的堆叠保存撤销信息,若有堆叠处理失败则返回非零退出码。
stack sync --continue-on-failurestack sync --keep-going同步输出特意以结果为导向。它应显示带有 、、 和 等图标的堆叠树,以及已更改的PR/备份/撤销说明。默认情况下不应显示内部阶段日志,如拉取、检查或协调。
●✓◌✕若重放失败, 会中止失败的樱桃拣选(cherry-pick),恢复原始分支,删除临时重放分支,保留备份和撤销日志,并告知用户在再次运行 前需要修复哪个分支。
stack syncstack sync请勿手动编辑 。若本地元数据过时,请运行 ;若预览内容正确,再运行 。
.git/stack/state.jsonstack sync --dry-runstack syncMerge The Stack Root
合并堆叠根PR
bash
stack merge
stack merge --apply
stack merge --auto
stack merge --auto --through stack-cPrefer omitting the branch. infers the root from the current stack
branch. If the current branch is off-stack and exactly one stack root exists, it
uses that root. If multiple roots exist, it asks for .
stack mergestack merge <branch>Use bare as a dry-run. Add only when the plan is correct.
Before merging, the command retargets immediate child PRs away from the root
branch so GitHub repo auto-delete settings are less likely to close descendants.
Use to retarget immediate child PRs, enable GitHub auto-merge, wait until
it lands, then repair descendants automatically.
Use to repeat that root merge flow through a
bounded target instead of merging the whole stack by default.
stack merge--apply--auto--auto --through <branch-or-pr>Mutating merge workflows stream progress while they run. Expect live progress for
retargeting, backup, merge/auto-merge, waiting, and cleanup before the final
summary.
bash
stack merge
stack merge --apply
stack merge --auto
stack merge --auto --through stack-c优先省略分支参数。 会从当前堆叠分支推断根PR。若当前分支不属于堆叠且恰好存在一个堆叠根,则使用该根;若存在多个根,则会提示使用 。
stack mergestack merge <branch>使用不带参数的 作为预演。仅当计划正确时才添加 参数。合并前,该命令会将直接子PR重新定位为不依赖根分支,这样GitHub仓库的自动删除设置就不太可能关闭子PR。使用 参数可重新定位直接子PR、启用GitHub自动合并、等待合并完成后自动修复子分支。
使用 可重复根PR合并流程,直到完成指定目标分支或PR的合并,而非默认合并整个堆叠。
stack merge--apply--auto--auto --through <branch-or-pr>修改类的合并工作流会在运行时流式显示进度。在最终摘要前,应显示重新定位、备份、合并/自动合并、等待和清理的实时进度。
Understand Or Undo The Last Mutation
查看或撤销最近的修改
bash
stack history
stack undo
stack undo --applyUse to inspect the saved undo journal. Use first as a dry-run,
then to restore branch tips, PR bases, and stack metadata.
historyundoundo --applybash
stack history
stack undo
stack undo --apply使用 查看已保存的撤销日志。先使用 进行预演,再使用 恢复分支尖端、PR基准和堆叠元数据。
historyundoundo --applyPR Body Stack Blocks
PR正文中的堆叠块
stack syncstack merge --apply/--automd
<!-- stack:links:start -->stack syncstack merge --apply/--automd
<!-- stack:links:start -->Stack
Stack
- #101
- #102
- #103 👈 current
Checked entries are landed history preserved from the previous block. Open PRs
stay unchecked until they are actually merged. The current PR is bold and marked
with `👈 current`. GitHub renders `#123` as a pull request link, so branch paths
are intentionally omitted from stack blocks.- #101
- #102
- #103 👈 current
已勾选的条目是从之前的块中保留的已合并历史。未关闭的PR会保持未勾选状态,直到实际合并。当前PR会加粗并标记 `👈 current`。GitHub会将 `#123` 渲染为拉取请求链接,因此堆叠块中特意省略了分支路径。Safety Rules
安全规则
- is dry-run by default.
stack merge - History-rewriting commands need , except
--applyis explicitly the high-level mutating workflow andstack syncwaits for GitHub.stack merge --auto - Never mutate trunk branches such as ,
dev, ormain.master - Before rebasing a branch, the tool creates a local backup branch.
- If output is unclear, inspect with ,
stack status, or command help before applying.stack history
- 默认是预演模式。
stack merge - 重写历史的命令需要添加 参数,除了
--apply是明确的高级修改工作流,以及stack sync会等待GitHub操作。stack merge --auto - 切勿修改主干分支,如 、
dev或main。master - 在重新定基分支前,工具会创建本地备份分支。
- 若输出不明确,请先使用 、
stack status或命令帮助进行检查,再执行修改操作。stack history
Do Not Use
请勿使用
Do not recommend GitHub's first-party command for this repair
workflow unless the user explicitly asks about itself. This skill is
for the local CLI.
gh stackgh stackstack除非用户明确询问 本身,否则不要推荐GitHub官方的 命令用于此修复工作流。本指南针对的是本地 CLI。
gh stackgh stackstack