graphite-stacks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraphite Stacks
Graphite 堆叠分支
Trunk-based development with stacked PRs using Graphite CLI.
<when_to_use>
- Creating or managing branch stacks
- Submitting stacked PRs
- Reorganizing branch relationships
- Addressing PR feedback across a stack
- Recovering from stack corruption
- Any command usage
gt
</when_to_use>
使用Graphite CLI进行基于主干的开发与堆叠PR管理。
<when_to_use>
- 创建或管理堆叠分支
- 提交堆叠PR
- 重组分支关联关系
- 处理堆叠分支中的PR反馈
- 从堆叠损坏中恢复
- 任何命令的使用场景
gt
</when_to_use>
Core Principle
核心原则
Use commands exclusively. Mixing and causes sync issues and divergent stacks. The only exception: for staging (or use flags).
gtgitgtgit add-a仅使用命令。 混合使用和会导致同步问题和堆叠分支不一致。唯一例外:可以使用暂存变更(或使用参数)。
gtgitgtgit add-aThis, Not That
正确操作 vs 错误操作
| Task | This | Not That |
|---|---|---|
| Create branch | | |
| Commit changes | | |
| Push to remote | | |
| Rebase stack | | |
| View stack | | |
| Switch branches | | |
| Amend commit | | |
| Multi-PR feedback | | Cherry-pick commits manually |
| 任务 | 正确操作 | 错误操作 |
|---|---|---|
| 创建分支 | | |
| 提交变更 | | |
| 推送到远程 | | |
| 变基堆叠分支 | | |
| 查看堆叠分支 | | |
| 切换分支 | | |
| 修改提交 | | |
| 多PR反馈处理 | | 手动拣选提交 |
Stack Lifecycle
堆叠分支生命周期
Create stack → Implement features → Submit PRs → Address feedback → Merge
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
gt create gt modify -acm gt submit gt absorb gt sync创建堆叠分支 → 实现功能 → 提交PR → 处理反馈 → 合并
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
gt create gt modify -acm gt submit gt absorb gt syncCreating Stacks
创建堆叠分支
bash
undefinedbash
undefinedNew branch with staged changes
基于已暂存变更创建新分支
gt create 'feature/step-1' -am "feat: first step"
gt create 'feature/step-1' -am "feat: first step"
Continue stacking
继续创建堆叠分支
gt create 'feature/step-2' -am "feat: second step"
gt create 'feature/step-3' -am "feat: third step"
gt create 'feature/step-2' -am "feat: second step"
gt create 'feature/step-3' -am "feat: third step"
Insert branch between current and child
在当前分支与子分支之间插入新分支
gt create 'feature/step-1.5' --insert -am "feat: inserted step"
undefinedgt create 'feature/step-1.5' --insert -am "feat: inserted step"
undefinedNavigation
分支导航
| Command | Action |
|---|---|
| Move up the stack (toward children) |
| Move down the stack (toward parent) |
| Jump to stack top |
| Jump to stack bottom |
| Interactive branch picker |
| 命令 | 操作 |
|---|---|
| 在堆叠分支中向上移动(指向子分支方向) |
| 在堆叠分支中向下移动(指向父分支方向) |
| 跳转到堆叠分支的最顶层 |
| 跳转到堆叠分支的最底层 |
| 交互式分支选择器 |
Modifying Branches
修改分支
bash
undefinedbash
undefinedAmend current branch (stages all)
修改当前分支(暂存所有变更)
gt modify -a
gt modify -a
New commit within same branch
在当前分支创建新提交
gt modify -acm "fix: address review feedback"
gt modify -acm "fix: address review feedback"
Commit to a different branch in the stack
提交变更到堆叠中的其他分支
git add path/to/file.ts
gt modify --into target-branch -m "feat: add file"
<rules>
**ALWAYS:**
- Use `gt create` for new branches
- Use `gt modify` for commits
- Use `gt submit` to push
- Use `gt restack` after parent changes
- Check `gt status` when uncertain
**NEVER:**
- Mix `git commit/push/rebase` with `gt` workflows
- Force push without understanding stack state
- Use `git rebase -i` (breaks Graphite metadata)
</rules>git add path/to/file.ts
gt modify --into target-branch -m "feat: add file"
<rules>
**必须遵守:**
- 使用`gt create`创建新分支
- 使用`gt modify`提交变更
- 使用`gt submit`推送变更
- 父分支变更后使用`gt restack`
- 不确定状态时查看`gt status`
**禁止操作:**
- 在`gt`工作流中混合使用`git commit/push/rebase`
- 不了解堆叠分支状态时强制推送
- 使用`git rebase -i`(会破坏Graphite元数据)
</rules>Addressing Review Feedback
处理评审反馈
Single PR: Navigate to branch, modify directly
bash
gt checkout target-branch
gt modify -acm "fix: address review comment"
gt submitMultiple PRs in stack: Use absorb from top
bash
gt top
git add .
gt absorb -a
gt submit --stackGraphite routes changes to correct branches based on file history.
单个PR: 导航到对应分支,直接修改
bash
gt checkout target-branch
gt modify -acm "fix: address review comment"
gt submit堆叠中的多个PR: 从顶层分支使用absorb命令
bash
gt top
git add .
gt absorb -a
gt submit --stackGraphite会根据文件历史将变更路由到正确的分支。
Reorganizing Stacks
重组堆叠分支
bash
undefinedbash
undefinedMove branch to different parent
将当前分支移动到新的父分支下
gt move --onto new-parent
gt move --onto new-parent
Move specific branch
将指定分支移动到目标分支下
gt move --source branch-name --onto target
gt move --source branch-name --onto target
After reorganization
重组完成后
gt restack
undefinedgt restack
undefinedSubmitting
提交PR
bash
undefinedbash
undefinedCurrent branch + downstack
当前分支及其下方的所有分支
gt submit
gt submit
Entire stack
整个堆叠分支
gt submit --stack
gt submit --stack
Non-interactive (automation)
非交互式模式(适用于自动化)
gt submit --no-interactive
undefinedgt submit --no-interactive
undefinedStack Visualization
堆叠分支可视化
bash
undefinedbash
undefinedJSON with parent relationships (preferred for scripts)
包含父分支关系的JSON格式(适合脚本使用)
gt status
gt status
Visual tree
可视化树形结构
gt ls
gt ls
Recent history
近期提交历史
gt log
undefinedgt log
undefinedSync and Maintenance
同步与维护
bash
undefinedbash
undefinedPull trunk, rebase stacks, clean merged
拉取主干分支、变基堆叠分支、清理已合并分支
gt sync
gt sync
Rebase branches onto updated parents
将分支变基到更新后的父分支
gt restack
gt restack
Undo last gt operation
撤销上一次gt操作
gt undo
undefinedgt undo
undefinedWhen Things Go Wrong
故障排查
Stack corruption symptoms:
- Branches appear as siblings instead of parent-child
- PRs contain wrong files
- shows unexpected structure
gt status
See recovery.md for step-by-step recovery procedures.
<references>
- commands.md - Quick command reference
- recovery.md - Stack corruption recovery
堆叠分支损坏的症状:
- 分支显示为同级而非父子关系
- PR包含错误的文件
- 显示异常结构
gt status
请参考recovery.md获取分步恢复指南。
<references>
- commands.md - 命令速查手册
- recovery.md - 堆叠分支损坏恢复指南