graphite
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraphite (gt) Skill
Graphite(gt)操作指南
This skill provides instructions for navigating branches and restacking stacks using Graphite ().
gt本指南提供了使用Graphite()进行分支导航和栈重排的操作说明。
gtCore Principles
核心原则
- Strictly Prohibited: NEVER run ,
gt ss, orgt submit. These commands are forbidden.gt squash - Navigation: Use commands to move between branches in a stack.
gt - Maintenance: Use for local stack maintenance and
gt restackorgt getfor syncing from remote.gt sync
- 严格禁止:绝对不要运行、
gt ss或gt submit命令,这些命令被禁用。gt squash - 导航:使用命令在栈中的各个分支间切换。
gt - 维护:使用进行本地栈维护,使用
gt restack或gt get与远程仓库同步。gt sync
Branch Navigation
分支导航
Use these commands to navigate through a stack of branches:
| Command | Action |
|---|---|
| Move to the branch immediately above the current one in the stack. |
| Move to the parent of the current branch. |
| Move to the previous branch in the stack, as ordered by |
| Move to the next branch in the stack, as ordered by |
| Move to the tip branch of the current stack. |
| Move to the branch closest to trunk in the current stack. |
| Display all tracked branches and their dependency relationships in a short format. |
使用以下命令在分支栈中进行导航:
| 命令 | 操作 |
|---|---|
| 切换到当前栈中位于当前分支的上一级分支。 |
| 切换到当前分支的父分支。 |
| 切换到当前栈中 |
| 切换到当前栈中 |
| 切换到当前栈的最顶端分支。 |
| 切换到当前栈中最接近主分支(trunk)的分支。 |
| 以简洁格式显示所有被追踪的分支及其依赖关系。 |
Stack Management
栈管理
Maintain your stack with these commands:
| Command | Action |
|---|---|
| Ensure each branch in the current stack has its parent in its Git commit history, rebasing if necessary. This maintains the local stack and does NOT reach out to upstream. |
| Sync a specific branch or stack from remote (trunk to branch). If no branch is provided, it syncs the current stack. |
| Sync all branches (including trunk) from remote and prompt to delete merged branches. |
使用以下命令维护你的分支栈:
| 命令 | 操作 |
|---|---|
| 确保当前栈中的每个分支的父分支都存在于其Git提交历史中,必要时执行变基操作。该命令仅维护本地栈,不会与上游仓库交互。 |
| 从远程仓库同步指定分支或栈(从主分支到目标分支)。若未指定分支,则同步当前栈。 |
| 从远程仓库同步所有分支(包括主分支),并提示删除已合并的分支。 |
Branch Management
分支管理
Use these commands to manage branches within your stack.
| Command | Action |
|---|---|
| Create a new branch with the given name and stack it on top of the current one. Always follow the |
| Rebase the current branch onto a target branch and restack descendants. Use |
| Split the current branch into multiple branches. This command is highly interactive. |
使用以下命令管理栈中的分支。
| 命令 | 操作 |
|---|---|
| 创建一个指定名称的新分支,并将其堆叠在当前分支之上。务必遵循 |
| 将当前分支变基到目标分支上,并重新堆叠其子分支。使用 |
| 将当前分支拆分为多个分支。该命令具有高度交互性。 |
Commit Management
提交管理
Use to manage commits within your stack. It automatically restacks descendants.
gt modify| Command | Action |
|---|---|
| Amend the head commit of the current branch. |
| Create a new commit on the current branch. Preferred for adding new changes while keeping history clean. |
使用管理栈中的提交,它会自动重新堆叠子分支。
gt modify| 命令 | 操作 |
|---|---|
| 修改当前分支的最新提交。 |
| 在当前分支上创建一个新提交。推荐使用此方式添加新更改,同时保持提交记录整洁。 |
Dealing with Interactivity
处理交互模式
Many Graphite commands (, , , ) are interactive by default, opening selectors, editors, or specialized menus.
gt modifygt movegt splitgt restack- For the Agent: Avoid using these commands in an interactive way. If a command requires user input that cannot be provided via flags (e.g., resolving complex rebase conflicts), stop and notify the user.
- Rebase Conflicts: If or
gt restackhits a conflict, Graphite will pause. Follow these steps to resolve:gt move- Locate Conflicts: Use or look at the error output to identify files with merge conflicts.
git status - Edit Files: Open the conflicting files and resolve the merge markers (,
<<<<<<<,=======). Ensure the code is functionally correct and includes necessary changes from both sides.>>>>>>> - Stage Changes: Run (or
gt add -A) to mark the conflicts as resolved.git add <file> - Continue: Run to resume the restack process. IMPORTANT: NEVER use
gt continueas Graphite tracks its own state.git rebase --continue - Verify: Once the restack completes, run tests to ensure the merged state is stable.
- Locate Conflicts: Use
- Interactive Selectors: Prefer providing explicit branch names or flags (like for
--onto) to avoid interactive selectors.gt move
许多Graphite命令(、、、)默认是交互模式,会打开选择器、编辑器或专用菜单。
gt modifygt movegt splitgt restack- 对于Agent:避免以交互方式使用这些命令。如果命令需要无法通过参数提供的用户输入(例如解决复杂的变基冲突),请停止操作并通知用户。
- 变基冲突:如果或
gt restack遇到冲突,Graphite会暂停。请按照以下步骤解决:gt move- 定位冲突:使用或查看错误输出,找出存在合并冲突的文件。
git status - 编辑文件:打开冲突文件,解决合并标记(、
<<<<<<<、=======)。确保代码功能正确,同时包含双方的必要更改。>>>>>>> - 暂存更改:运行(或
gt add -A)标记冲突已解决。git add <file> - 继续操作:运行恢复栈重排过程。重要提示:绝对不要使用
gt continue,因为Graphite会追踪自身的状态。git rebase --continue - 验证:栈重排完成后,运行测试确保合并后的状态稳定。
- 定位冲突:使用
- 交互选择器:优先提供明确的分支名称或参数(例如的
gt move参数),避免使用交互选择器。--onto
Common Fixes & Lessons
常见问题修复与经验总结
Using Graphite over Git
使用Graphite而非Git原生命令
The Problem: Using standard or fails to update Graphite's internal stack metadata and does not trigger automatic restacking of descendants. This can lead to a desynchronized stack where Graphite is unaware of the new commits or changes.
git commitgit commit --amendThe Solution: Always prefer commands over their standard counterparts for commit and branch management.
gtgit- Creating a new branch: Use instead of
gt create <branch-name>.git checkout -b <branch-name> - Creating a new commit: Use instead of
gt modify -c -m "message".git commit -m "message" - Amending a commit: Use instead of
gt modify --amend.git commit --amend - Staging and committing everything: Use instead of
gt modify -cam "message".git commit -am "message"
Benefits:
- Metadata Integrity: Graphite keeps its internal view of the stack consistent.
- Automatic Restacking: Descendant branches are automatically updated if you change a parent branch.
- Visual Clarity: Graphite's CLI output stays accurate and helpful.
问题:使用标准的或不会更新Graphite的内部栈元数据,也不会自动重新堆叠子分支。这会导致栈不同步,Graphite无法感知新的提交或更改。
git commitgit commit --amend解决方案:在进行提交和分支管理时,始终优先使用命令而非Git原生命令。
gt- 创建新分支:使用而非
gt create <branch-name>。git checkout -b <branch-name> - 创建新提交:使用而非
gt modify -c -m "提交信息"。git commit -m "提交信息" - 修改提交:使用而非
gt modify --amend。git commit --amend - 暂存并提交所有更改:使用而非
gt modify -cam "提交信息"。git commit -am "提交信息"
优势:
- 元数据完整性:Graphite对栈的内部视图保持一致。
- 自动重排:若你修改了父分支,子分支会自动更新。
- 视觉清晰度:Graphite的CLI输出始终准确且有帮助。
Misplaced Commits
提交位置错误
If you accidentally commit a change to the wrong branch in a stack:
- Stash uncommitted changes: If you have uncommitted work, to keep it safe.
git stash - Move the change to a new branch (if the commit belongs in its own new branch):
- to safely move the head.
gt create <new-branch> - to move back to the parent.
gt down - (Safe now because the commit is preserved in the new branch).
git reset --hard HEAD~1
- Move to an existing branch:
- (Soft reset to keep changes in the working tree).
git reset HEAD~1 - /
gt downto the target branch.gt up - or
gt modify -cto incorporate the changes.gt modify --amend
- Restore stashed changes: to resume your work.
git stash pop - Repair the stack: Move back to the tip and run to ensure all descendant branches are updated with the parent's new state.
gt restack
如果你不小心将更改提交到了栈中的错误分支:
- 暂存未提交的更改:若有未提交的工作,使用保存。
git stash - 将更改移动到新分支(如果该提交应属于一个新分支):
- 运行以安全移动最新提交。
gt create <new-branch> - 运行回到父分支。
gt down - 运行(现在操作是安全的,因为提交已保留在新分支中)。
git reset --hard HEAD~1
- 运行
- 移动到现有分支:
- 运行(软重置,将更改保留在工作区)。
git reset HEAD~1 - 使用/
gt down切换到目标分支。gt up - 使用或
gt modify -c合并更改。gt modify --amend
- 运行
- 恢复暂存的更改:运行继续你的工作。
git stash pop - 修复栈:切换到栈的顶端分支,运行确保所有子分支都已更新为父分支的新状态。
gt restack
Prohibited Commands
禁止使用的命令
[!CAUTION] DO NOT use the following commands under any circumstances:
gt ssgt submitgt squash
These commands are strictly forbidden to ensure that PR submission, updates, and branch squashing are handled manually or through specified workflows.
[!CAUTION] 绝对不要在任何情况下使用以下命令:
gt ssgt submitgt squash
这些命令被严格禁用,以确保PR提交、更新和分支合并操作通过手动方式或指定工作流处理。