gg
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesegg
gg
Use this skill to operate git-gud () as a CLI tool for day-to-day stacked-diff workflows across GitHub and GitLab.
gg使用本技能操作git-gud()作为CLI工具,在GitHub和GitLab上完成日常的堆叠差异工作流。
ggWhen to use
适用场景
- You need multiple PRs/MRs that depend on each other
- You need to sync stack changes and keep review metadata updated (including GG-ID/GG-Parent normalization)
- You need machine-readable command output for automation ()
--json
- 你需要多个相互依赖的PR/MR
- 你需要同步堆叠变更并更新评审元数据(包括GG-ID/GG-Parent标准化)
- 你需要机器可读的命令输出用于自动化(参数)
--json
Prerequisites
前置条件
- installed
gg - Provider CLI installed + authenticated:
- GitHub:
gh auth status - GitLab:
glab auth status
- GitHub:
- Git repo with initialized (
gg)gg setup
Note: Network errors during auth check are non-fatal — gg prints a warning and continues. The operation may fail later if authentication is actually required.
- 已安装
gg - 已安装并认证对应的提供商CLI:
- GitHub:
gh auth status - GitLab:
glab auth status
- GitHub:
- 已通过初始化的Git仓库
gg setup
注意: 认证检查期间的网络错误不会导致程序终止——gg会打印警告并继续执行。如果后续操作确实需要认证,可能会失败。
Setup
配置
Interactive wizard (recommended)
交互式向导(推荐)
bash
gg setup # Quick mode: essential settings (provider, base, username)
gg setup --all # Full mode: all settings organized by categoryQuick mode prompts for: provider, base branch, username.
Full mode organizes all settings into groups: General, Sync, Land, Lint, Worktrees, and GitLab (if applicable). Includes sync_draft, sync_update_descriptions, and sync_update_title options.
bash
gg setup # 快速模式:仅配置必要项(提供商、基础分支、用户名)
gg setup --all # 完整模式:按类别配置所有设置快速模式会提示你输入:提供商、基础分支、用户名。
完整模式将所有设置分为以下组别:通用、同步、合并、检查、工作树,以及GitLab专属设置(若适用)。包含sync_draft、sync_update_descriptions和sync_update_title等选项。
Global config
全局配置
Store shared defaults in that apply to all repos. Local config () takes precedence.
~/.config/gg/config.jsongg setup将共享默认配置存储在中,适用于所有仓库。本地配置(通过设置)优先级更高。
~/.config/gg/config.jsongg setupManual setup (.git/gg/config.json
)
.git/gg/config.json手动配置(.git/gg/config.json
)
.git/gg/config.jsonjson
{
"defaults": {
"provider": "github",
"base": "main",
"branch_username": "your-github-user",
"lint": ["cargo fmt --all --check", "cargo clippy -- -D warnings"],
"auto_add_gg_ids": true,
"sync_auto_rebase": false,
"sync_behind_threshold": 1,
"sync_auto_lint": false,
"sync_draft": false,
"sync_update_descriptions": true,
"sync_update_title": false,
"land_auto_clean": false,
"land_wait_timeout_minutes": 30,
"unstaged_action": "ask"
}
}json
{
"defaults": {
"provider": "gitlab",
"base": "main",
"branch_username": "your-gitlab-user",
"lint": ["cargo fmt --all --check", "cargo clippy -- -D warnings"],
"gitlab": {
"auto_merge_on_land": false
}
}
}auto_add_gg_idsjson
{
"defaults": {
"provider": "github",
"base": "main",
"branch_username": "your-github-user",
"lint": ["cargo fmt --all --check", "cargo clippy -- -D warnings"],
"auto_add_gg_ids": true,
"sync_auto_rebase": false,
"sync_behind_threshold": 1,
"sync_auto_lint": false,
"sync_draft": false,
"sync_update_descriptions": true,
"sync_update_title": false,
"land_auto_clean": false,
"land_wait_timeout_minutes": 30,
"unstaged_action": "ask"
}
}json
{
"defaults": {
"provider": "gitlab",
"base": "main",
"branch_username": "your-gitlab-user",
"lint": ["cargo fmt --all --check", "cargo clippy -- -D warnings"],
"gitlab": {
"auto_merge_on_land": false
}
}
}auto_add_gg_idsCore workflow
核心工作流
- Create/switch stack (prefer worktree):
bash
gg co -w feature-authWhen shell integration is installed (, , or ), changes into the stack worktree after checkout succeeds. Without it, read the printed worktree path and there before editing.
eval "$(gg init zsh)"eval "$(gg init bash)"gg init fish | sourcegg co -wcdWhen splitting an existing stack into lower and upper stacks, prefer a managed
worktree for the new upper stack:
bash
gg unstack --target 3 --name feature-auth-followup --wt- Commit logical changes:
bash
git add <files>
git commit -m "feat: add input validation"- Check stack state:
bash
gg ls --json # single-stack details + summary metrics
gg log --json # smartlog-style view of the current stack
gg inbox --json # cross-stack triage buckets for action needed- Publish/update PR/MR chain:
bash
gg sync --jsonIf a mapped PR/MR still points at an old source branch after a stack split,
recreates that PR/MR with the current entry branch, remaps config to
the new number, comments on the old one, and closes it. JSON action is
.
gg sync"recreated"If returns a warning that the stack branch does not use the
configured prefix, surface it to the user. The command may continue, but stack
discovery/listing and saved PR/MR mappings can be inaccurate until the branch is
renamed to match .
gg sync --jsondefaults.branch_username- When approved + green CI, land only after user confirmation:
bash
gg land -a -c --json- 创建/切换堆叠(优先使用工作树):
bash
gg co -w feature-auth当安装了Shell集成(, , 或 )后,会在检出成功后切换到堆叠工作树。未安装时,请查看打印的工作树路径,在编辑前通过命令进入该路径。
eval "$(gg init zsh)"eval "$(gg init bash)"gg init fish | sourcegg co -wcd当将现有堆叠拆分为下层和上层堆叠时,优先为新的上层堆叠使用托管工作树:
bash
gg unstack --target 3 --name feature-auth-followup --wt- 提交逻辑变更:
bash
git add <files>
git commit -m "feat: add input validation"- 检查堆叠状态:
bash
gg ls --json # 单堆叠详情 + 汇总指标
gg log --json # 当前堆叠的智能日志视图
gg inbox --json # 跨堆叠分类待处理事项- 发布/更新PR/MR链:
bash
gg sync --json如果在堆叠拆分后,映射的PR/MR仍然指向旧的源分支,会使用当前条目分支重新创建该PR/MR,将配置重新映射到新编号,在旧PR/MR上添加评论并关闭它。JSON输出中的操作类型为。
gg sync"recreated"如果返回警告,提示堆叠分支未使用配置的前缀,请告知用户。命令可能会继续执行,但直到分支重命名为匹配的格式后,堆叠发现/列表以及已保存的PR/MR映射才会准确。
gg sync --jsondefaults.branch_username- 当PR/MR获批且CI通过后,仅在用户确认后合并:
bash
gg land -a -c --jsonAgent operating rules (mandatory)
Agent操作规则(强制)
- Never run without explicit user confirmation.
gg land - Always use for
--json,gg ls,gg sync,gg land, andgg clean -a.gg lint - Prefer worktrees for isolation (). If shell integration is unavailable, manually
gg co -w <stack>to the printed worktree path before editing.cd - Verify and
approved: truesuccess before landing. If the user requestsci_status, skip the approval check (GitHub only — GitLab ignores the flag).--admin - If sync warns stack is behind base, run first.
gg rebase - Prefer for multi-commit edits.
gg absorb -s - Never use blindly. Review
git add -Afirst and only stage intended files. Usegit statusto avoid leaking secrets, env files, or unrelated changes.git add <specific-files> - Respect the immutability guard. Rewrite-style commands (,
gg sc,gg absorb/gg reorder,gg arrange,gg split,gg unstack,gg drop,gg rebase) refuse to rewrite merged PRs/MRs or commits already on the base branch, except thatgg restacksilently skips base-ancestor commits that naturally drop out when rebasing onto the refreshed base. If a command exits withgg rebase, surface the listed commits and reasons to the user and get explicit confirmation before retrying withImmutableTargets/-f(alias--force). If the error comes from--ignore-immutable's auto-rebase, the override isgg sync/gg rebase --force, notgg rebase --ignore-immutable.gg sync --force
- 未经用户明确确认,绝不要运行命令。
gg land - 对于、
gg ls、gg sync、gg land和gg clean -a命令,始终使用gg lint参数。--json - 优先使用工作树来实现隔离()。如果Shell集成不可用,请在编辑前手动
gg co -w <stack>到打印的工作树路径。cd - 合并前需验证和
approved: true为成功状态。如果用户要求使用ci_status参数,则跳过审批检查(仅GitHub支持——GitLab会忽略该标志)。--admin - 如果同步时警告堆叠落后于基础分支,请先运行。
gg rebase - 多提交编辑优先使用。
gg absorb -s - 绝不要盲目使用。 先查看
git add -A,仅暂存目标文件。使用git status避免泄露密钥、环境文件或无关变更。git add <specific-files> - 遵循不可变保护机制。 重写类命令(、
gg sc、gg absorb/gg reorder、gg arrange、gg split、gg unstack、gg drop、gg rebase)会拒绝重写已合并的PR/MR或已在基础分支上的提交,除了gg restack会自动跳过在重新基于更新后的基础分支时自然会被丢弃的基础祖先提交。如果命令因gg rebase错误退出,请向用户列出相关提交及原因,并在使用ImmutableTargets/-f(别名--force)重试前获得明确确认。如果错误来自--ignore-immutable的自动重基,则需要通过gg sync/gg rebase --force覆盖,而非gg rebase --ignore-immutable。gg sync --force
Common operations
常见操作
- Navigate: ,
gg mv,gg first,gg last,gg prevgg next - Amend current commit: /
gg scgg sc -a - Auto-distribute staged hunks:
gg absorb -s - Split a commit into two: — opens a two-panel TUI for hunk selection (files on the left, colored diff on the right), followed by inline commit message inputs for both the new and remainder commits. Use
gg splitto fall back to sequential--no-tuistyle prompts. Thegit add -pflag bypasses the TUI message input for the new commit. The-mflag skips the remainder message input. Pass--no-editto auto-select all hunks from those files (e.g.,FILES...).gg split -c 3 file1.rs file2.rs - Split a stack into two stacks: — opens a picker by default. The selected entry and descendants become a new independent stack; lower entries remain in the original stack. Use
gg unstackfor scripts, and--target <position|gg-id|sha> --no-tuito choose the new stack name.--name <stack> - Drop commits from stack: (alias:
gg drop <position|sha|gg-id>... -y). Usegg abandon/-yto skip confirmation; add--yes/-fonly to bypass the immutability guard for merged/base-ancestor commits.--force - Reorder/drop stack (TUI): (or
gg reorder) — opens interactive TUI for visual reordering and dropping commits. Pressgg arrangeto mark a commit for dropping. Usedto fall back to text editor (delete lines to drop).--no-tui - Reorder stack (direct):
gg reorder -o "3,1,2" - Sync subset:
gg sync -u <position|gg-id|sha> --json - Lint stack:
gg lint --json - Run a command across the stack: (see below)
gg run -- <cmd...> - Triage multiple stacks at once:
gg inbox --json - Repair ancestry drift: /
gg restack(see below)gg restack --dry-run --json - Clean merged stacks:
gg clean -a --json - Undo last local mutation: (see below)
gg undo
- 导航:,
gg mv,gg first,gg last,gg prevgg next - 修改当前提交:/
gg scgg sc -a - 自动分配暂存块:
gg absorb -s - 将一个拆分为两个提交:—— 打开双面板TUI用于选择代码块(左侧为文件,右侧为带颜色的差异),随后为新提交和剩余提交输入内联提交信息。使用
gg split参数回退到顺序式--no-tui风格的提示。git add -p参数跳过新提交的TUI信息输入。-m参数跳过剩余提交的信息输入。传入--no-edit可自动选择这些文件的所有代码块(例如:FILES...)。gg split -c 3 file1.rs file2.rs - 将一个堆叠拆分为两个堆叠:—— 默认打开选择器。选中的条目及其子条目将成为新的独立堆叠;下层条目保留在原堆叠中。对于脚本,使用
gg unstack参数,使用--target <position|gg-id|sha> --no-tui参数指定新堆叠的名称。--name <stack> - 从堆叠中删除提交:(别名:
gg drop <position|sha|gg-id>... -y)。使用gg abandon/-y参数跳过确认;仅当需要绕过已合并/基础祖先提交的不可变保护时,添加--yes/-f参数。--force - 重新排序/删除堆叠(TUI):(或
gg reorder)—— 打开交互式TUI用于可视化重新排序和删除提交。按gg arrange键标记要删除的提交。使用d参数回退到文本编辑器(删除行即可删除提交)。--no-tui - 直接重新排序堆叠:
gg reorder -o "3,1,2" - 同步子集:
gg sync -u <position|gg-id|sha> --json - 检查堆叠:
gg lint --json - 在整个堆叠中运行命令:(详见下文)
gg run -- <cmd...> - 同时分类多个堆叠:
gg inbox --json - 修复祖先漂移:/
gg restack(详见下文)gg restack --dry-run --json - 清理已合并的堆叠:
gg clean -a --json - 撤销上次本地变更:(详见下文)
gg undo
Undoing local mutations (gg undo
)
gg undo撤销本地变更(gg undo
)
gg undogg undoHEADgg<commondir>/gg/operations/*.jsonbash
gg undo # reverse the most recent local operation
gg undo --list # see recent operations (newest-first)
gg undo <op_id> # target a specific record from --list
gg undo; gg undo # redo: a second undo reverses the first
gg undo --json # machine-readable outputEvery mutating command (, , , , , ,
, , , , nav, , , ,
and ) snapshots the refs it will touch before mutating and
records the operation on success. The log keeps the last 100 records;
interrupted/pending records are never pruned.
scdropsplitunstackrebasereorderabsorbreconcilerestackcheckoutcleansynclandrun --amendRefusal modes (exit 1, no refs touched, JSON includes ):
refusal.reason- — target operation pushed/merged/closed/created a PR/MR. gg prints a provider-specific revert hint (
remote,gh pr close <n>,glab mr close <n>). Agents must surface the hint to the user rather than attempt silent remote rollback.git push --delete … - — operation crashed or was Ctrl-C'd mid-flight.
interrupted - — refs moved since the target operation finalised. The error names the ref, expected OID, and actual OID.
stale - — record was written by a newer
unsupported_schemabinary.gg
gg undogit refloggit stash--all--rangegg undo<commondir>/gg/operations/*.jsonggHEADbash
gg undo # 撤销最近一次本地操作
gg undo --list # 查看最近操作(按时间倒序)
gg undo <op_id> # 针对--list中的特定记录进行撤销
gg undo; gg undo # 重做:再次撤销会恢复之前的操作
gg undo --json # 机器可读输出所有变更类命令(、、、、、、、、、、导航命令、、、以及)都会在变更前快照其将修改的引用,并在成功执行后记录该操作。日志保留最近100条记录;中断/未完成的记录绝不会被删除。
scdropsplitunstackrebasereorderabsorbreconcilerestackcheckoutcleansynclandrun --amend拒绝模式(退出码1,不修改任何引用,JSON输出包含):
refusal.reason- —— 目标操作推送/合并/关闭/创建了PR/MR。gg会打印提供商特定的撤销提示(如
remote、gh pr close <n>、glab mr close <n>)。Agent必须将该提示告知用户,而非尝试静默回滚远程操作。git push --delete … - —— 操作在执行过程中崩溃或被Ctrl-C中断。
interrupted - —— 自目标操作完成后,引用已被修改。错误信息会列出引用名称、预期OID和实际OID。
stale - —— 记录由更新版本的
unsupported_schema二进制文件写入。gg
gg undogit refloggit stash--all--rangeRepairing stack ancestry (gg restack
)
gg restack修复堆叠祖先关系(gg restack
)
gg restackgg restackGG-Parentgit rebasegit commit --amendbash
gg restack --dry-run # show plan without changes
gg restack --dry-run --json # machine-readable plan
gg restack # execute full ancestry repair
gg restack --from 3 # repair only from position 3 upward
gg restack --json # execute with JSON outputEach step in the plan is one of:
- ok — parent already correct, no action needed
- reattach — parent differs, needs rebasing
- skip — below threshold, not checked
--from
After a successful restack, run to push the repaired commits.
gg syncgg restackGG-Parentgit rebasegit commit --amendbash
gg restack --dry-run # 显示修复计划但不执行变更
gg restack --dry-run --json # 机器可读的修复计划
gg restack # 执行完整的祖先修复
gg restack --from 3 # 仅从第3个位置开始向上修复
gg restack --json # 执行并输出JSON格式结果计划中的每个步骤为以下类型之一:
- ok —— 父提交已正确,无需操作
- reattach —— 父提交不匹配,需要重基
- skip —— 低于阈值,不检查
--from
成功修复后,运行推送修复后的提交。
gg syncRunning commands across the stack (gg run
)
gg run在整个堆叠中运行命令(gg run
)
gg rungg runlint- Read-only (default): Each commit is checked out, the command runs, and the tree must stay clean. Any modification fails that commit (same contract as
gg run -- cargo test -p mycratewithoutgg lint).--amend - Amend mode: Changes the command makes are folded into each commit via
gg run --amend -- cargo fmt, then the rest of the stack is rebased on top. This is the same enginegit commit --amenduses.gg lint - Discard mode: Runs the command and throws away any changes (working tree + index + untracked). Useful when you only care about the exit code of a command that happens to mutate state.
gg run --discard -- ./mutating-check.sh - Stop on first failure (default) vs keep going:
Add /
--keep-goingto continue through failing commits instead of aborting at the first one.-k - Limit how far you go: stops after the named commit. Everything above it is left untouched.
--until <position|gg-id|sha> - Parallelize read-only runs: /
-j Nspawns isolated worktrees per commit. Valid only with the default (read-only) mode. The dirty-tree check in each worker matches the sequential path (untracked files are ignored, tracked modifications fail).--jobs N - JSON output: emits a single
gg run --json -- <cmd...>document on stdout (seeRunResponse). Failures setreference.md; the process still exits non-zero, but only the run payload is printed — no trailingrun.all_passed = falseobject.{"error":...}
Argument boundaries are preserved:
passes exactly those argv elements to without shell splitting, so
quoted args with spaces, globs, or shell metacharacters go through
intact. Use before the command (as shown) so clap treats
subsequent tokens as the command, not as flags.
gg run -- git commit -m "multi word"git--gg runFor repeatable linter runs with commands configured in ,
prefer — it's with the command list coming from
config.
.git/gg/config.jsongg lintgg run --amendgg runlint- 只读模式(默认):每个提交都会被检出,执行命令,且工作树必须保持干净。任何修改都会导致该提交执行失败(与未使用
gg run -- cargo test -p mycrate参数的--amend规则相同)。gg lint - 修改模式:命令产生的变更会通过
gg run --amend -- cargo fmt合并到每个提交中,然后将堆叠的其余部分重新基于该提交。这与git commit --amend使用的引擎相同。gg lint - 丢弃模式:执行命令并丢弃所有变更(工作树 + 索引 + 未跟踪文件)。适用于仅关心命令退出码,而命令本身会修改状态的场景。
gg run --discard -- ./mutating-check.sh - 首次失败即停止(默认)vs 继续执行:
添加/
--keep-going参数可继续执行后续提交,而非在首次失败时终止。-k - 限制执行范围:参数会在指定提交后停止执行。该提交之上的所有内容保持不变。
--until <position|gg-id|sha> - 并行化只读执行:/
-j N参数会为每个提交创建独立的工作树。仅适用于默认(只读)模式。每个工作树中的脏树检查与顺序执行一致(忽略未跟踪文件,跟踪文件的修改会导致失败)。--jobs N - JSON输出:会在标准输出中输出单个
gg run --json -- <cmd...>文档(详见RunResponse)。执行失败时会设置reference.md;进程仍会返回非零退出码,但仅会打印执行负载——不会附加run.all_passed = false对象。{"error":...}
参数边界会被保留:会将这些参数完整传递给,不会进行Shell拆分,因此包含空格、通配符或Shell元字符的带引号参数会完整传递。请在命令前使用(如示例所示),以便clap将后续标记视为命令而非的参数。
gg run -- git commit -m "multi word"git--gg run对于可重复的检查器运行,且命令配置在中,优先使用——它相当于从配置中读取命令列表的。
.git/gg/config.jsongg lintgg run --amendImmutable commits
不可变提交
gg refuses by default to rewrite commits that look "already published":
- the tracked PR/MR is merged, or
- the commit is already reachable from (or the local base, as a fallback).
origin/<base>
The guard protects , , / ,
, , , , and . is a special case: merged commits (both base-ancestor commits and squash-merged PRs) are silently skipped because would drop them naturally via patch-id matching instead of rewriting them. For the remaining commands the command exits with an error listing every affected position, short SHA, title, and reason (e.g. , ).
gg scgg absorbgg reordergg arrangegg splitgg unstackgg dropgg rebasegg restackgg rebasegit rebaseImmutableTargetsmerged as !123already in origin/mainTo bypass it intentionally, pass / (long alias
). Always surface the listed commits and reasons to the
user first; the override still emits a warning and proceeds.
-f--force--ignore-immutableIf surfaces the guard during auto-rebase, run or
after user confirmation, then retry .
only affects push behavior.
gg syncgg rebase --forcegg rebase --ignore-immutablegg syncgg sync --forcegg landgg absorb --dry-runreference.md默认情况下,gg会拒绝重写看起来“已发布”的提交:
- 对应的PR/MR已合并,或
- 提交已可从(或本地基础分支,作为备选)访问。
origin/<base>
该保护机制适用于、、/、、、、和命令。是特殊情况:已合并的提交(包括基础祖先提交和 squash合并的PR)会被自动跳过,因为会通过patch-id匹配自然丢弃它们,而非重写。对于其他命令,命令会因错误退出,并列出所有受影响的位置、短SHA、标题和原因(例如、)。
gg scgg absorbgg reordergg arrangegg splitgg unstackgg dropgg rebasegg restackgg rebasegit rebaseImmutableTargetsmerged as !123already in origin/main若要有意绕过该机制,请传递/(长别名)参数。请始终先向用户列出相关提交及原因;即使使用覆盖参数,命令仍会发出警告并继续执行。
-f--force--ignore-immutable如果在自动重基时触发该保护机制,请在用户确认后运行或,然后重试。仅影响推送行为。
gg syncgg rebase --forcegg rebase --ignore-immutablegg syncgg sync --forcegg landgg absorb --dry-runreference.mdPR/MR body ownership
PR/MR正文所有权
gg sync(user content — preserved across syncs)
<!-- gg:managed:start -->
(generated by gg — regenerated on every sync)
<!-- gg:managed:end -->
(user content — preserved across syncs)- New PRs/MRs: Body is wrapped in managed markers automatically.
- Re-sync with markers: Only the managed block is replaced; user content above/below is preserved.
- Legacy PRs (no markers): Body is left untouched with a warning — no risk of clobbering manual edits.
- Content inside the managed block is regenerated on each sync. Place persistent checklists and notes outside the markers.
gg sync(用户内容 —— 同步时会保留)
<!-- gg:managed:start -->
(由gg生成 —— 每次同步都会重新生成)
<!-- gg:managed:end -->
(用户内容 —— 同步时会保留)- 新PR/MR:正文会自动被托管标记包裹。
- 带标记的重新同步:仅托管块会被替换;标记上下的用户内容会保留。
- 旧PR(无标记):正文保持不变并发出警告——不会覆盖手动编辑内容。
- 托管块内的内容:每次同步都会重新生成。请将持久化的检查清单和注释放在标记之外。
Stack-navigation comments
堆叠导航评论
If the repo's has ,
posts and maintains a managed comment on each open PR/MR in the
stack. The comment lists every entry ( on GitHub, on GitLab) with a
👉 marker on the current one. The comment is identified by a hidden
marker and managed entirely by git-gud — don't edit
these comments manually, and don't be surprised when adds, updates,
or removes them automatically.
.git/gg/config.jsondefaults.stack_nav_comments: truegg sync#N!N<!-- gg:stack-nav -->gg syncDisable the feature by setting (the
default). The next then cleans up any existing managed comments.
Reconcile is skipped under to avoid partial-stack inconsistencies.
defaults.stack_nav_comments: falsegg sync--until如果仓库的中设置了,会在堆叠中的每个开放PR/MR上发布并维护一条托管评论。该评论会列出每个条目(GitHub为,GitLab为),并在当前条目旁标注👉标记。该评论通过隐藏的标记识别,完全由git-gud管理——请勿手动编辑这些评论,也无需惊讶会自动添加、更新或删除它们。
.git/gg/config.jsondefaults.stack_nav_comments: truegg sync#N!N<!-- gg:stack-nav -->gg sync通过设置(默认值)可禁用该功能。下次会清理所有现有的托管评论。使用参数时会跳过协调,以避免部分堆叠不一致。
defaults.stack_nav_comments: falsegg sync--untilGitLab-specific
GitLab专属特性
- is GitLab-only and requests queueing/auto-merge.
gg land --auto-merge - With merge trains enabled, landing may enqueue MRs instead of immediate merge.
- After queueing, GitLab may temporarily omit the MR from the merge-train listing. Treat the "not reported yet; still polling" status as non-terminal unless the command reports closed, skipped, failed CI, timeout, or repeated API errors.
gg land --wait - Track train state in with:
gg ls --jsonin_merge_trainmerge_train_position
- Land action values on GitLab may include /
queued(in addition toalready_queued).merged - When detects CI failure, the error message includes the names and stages of failed pipeline jobs (fetched from the MR's head pipeline).
--wait - After landing an MR, downstream MRs are automatically retargeted away from the merged branch — no manual retargeting in GitLab UI is needed. also handles this if an MR was merged directly in the UI.
gg sync - Use for auxiliary GitLab checks/actions.
glab - JSON fields always use naming, even for GitLab MRs (
pr_*,pr_number).pr_state
- 是GitLab专属功能,用于请求排队/自动合并。
gg land --auto-merge - 启用合并队列后,合并操作可能会将MR加入队列而非立即合并。
- 加入队列后,GitLab可能会暂时在合并队列列表中省略该MR。除非命令报告已关闭、已跳过、CI失败、超时或重复API错误,否则请将的“尚未报告;仍在轮询”状态视为非终止状态。
gg land --wait - 通过跟踪队列状态,相关字段:
gg ls --jsonin_merge_trainmerge_train_position
- GitLab上的合并操作值可能包括/
queued(除already_queued外)。merged - 当检测到CI失败时,错误信息会包含失败流水线作业的名称和阶段(从MR的头流水线获取)。
--wait - 合并MR后,下游MR会自动重新定向,不再指向已合并的分支——无需在GitLab UI中手动重新定向。如果MR是直接在UI中合并的,也会处理该情况。
gg sync - 使用进行辅助GitLab检查/操作。
glab - JSON字段始终使用命名,即使是GitLab MR(如
pr_*、pr_number)。pr_state
Provider-neutral notes
提供商中立说明
- values:
pr_state,open,merged,closed(same for both GitHub and GitLab).draft - format varies by provider (
pr_urlfor GitHub,/pull/Nfor GitLab)./-/merge_requests/N
- 取值:
pr_state、open、merged、closed(GitHub和GitLab一致)。draft - 格式因提供商而异(GitHub为
pr_url,GitLab为/pull/N)。/-/merge_requests/N
See also
另请参阅
- Full command + schema reference:
reference.md - End-to-end walkthrough:
examples/basic-flow.md - Multi-commit editing:
examples/multi-commit.md - Merge trains (GitLab):
examples/merge-train.md - MCP server tools & schemas: → MCP Server section
reference.md
- 完整命令 + 架构参考:
reference.md - 端到端演练:
examples/basic-flow.md - 多提交编辑:
examples/multi-commit.md - 合并队列(GitLab):
examples/merge-train.md - MCP服务器工具与架构:→ MCP Server章节
reference.md
MCP Server Usage for Agents
Agent使用MCP服务器
The binary exposes git-gud as an MCP server (stdio transport). Set to the target repo.
gg-mcpGG_REPO_PATHgg-mcpGG_REPO_PATHRead-only tools (safe, no side effects)
只读工具(安全,无副作用)
- /
stack_list/stack_log/stack_list_all— inspect stacks (stack_statusgives a smartlog-style view of the current stack;stack_logis cross-stack)stack_list_all - — check PR state, CI, approval
pr_info - — read repo configuration
config_show - — list recent operations from the per-repo operation log
stack_undo_list
- /
stack_list/stack_log/stack_list_all—— 检查堆叠(stack_status提供当前堆叠的智能日志视图;stack_log为跨堆叠视图)stack_list_all - —— 检查PR状态、CI、审批情况
pr_info - —— 读取仓库配置
config_show - —— 从仓库操作日志中列出最近操作
stack_undo_list
Write tools (mutating, use with care)
写入工具(会修改数据,谨慎使用)
- — create or switch stacks
stack_checkout - — push and create/update PRs (use
stack_syncfor safety)draft: true - — merge approved PRs (always confirm with user first)
stack_land - — remove merged stacks
stack_clean - — rebase onto latest base
stack_rebase - /
stack_squash— amend commitsstack_absorb - — fix out-of-sync remote branches (pass
stack_reconcileto skip the metadata normalization confirmation prompt in non-interactive/MCP contexts; this does not bypass safety checks or immutability protections)yes: true - — remove commits from the stack (always passes
stack_drop; set--yesonly to bypass the immutability guard for merged/base commits; agent confirms with user before any drop)force: true - — split a commit using interactive hunk selection (TUI opens by default; pass FILES... to auto-select all hunks for those files)
stack_split - — reorder commits with explicit order string (no TUI)
stack_reorder - — repair stack ancestry drift (
stack_restack,dry_runparams)from - — reverse the ref/HEAD effects of the most recent mutating
stack_undocommand (refuses on remote-touching ops, returns provider-specific revert hints; agents must surface those hints rather than attempt silent remote rollback)gg
- —— 创建或切换堆叠
stack_checkout - —— 推送并创建/更新PR(为安全起见,使用
stack_sync)draft: true - —— 合并已获批的PR(必须先获得用户确认)
stack_land - —— 删除已合并的堆叠
stack_clean - —— 重新基于最新的基础分支
stack_rebase - /
stack_squash—— 修改提交stack_absorb - —— 修复不同步的远程分支(在非交互式/MCP环境中,传递
stack_reconcile可跳过元数据标准化确认提示;这不会绕过安全检查或不可变保护)yes: true - —— 从堆叠中删除提交(始终传递
stack_drop;仅当需要绕过已合并/基础提交的不可变保护时,设置--yes;Agent在执行任何删除操作前需获得用户确认)force: true - —— 通过交互式代码块选择拆分提交(默认打开TUI;传入FILES...可自动选择这些文件的所有代码块)
stack_split - —— 使用明确的顺序字符串重新排序提交(无TUI)
stack_reorder - —— 修复堆叠祖先漂移(支持
stack_restack、dry_run参数)from - —— 撤销最近一次变更类
stack_undo命令对引用/HEAD的影响(会拒绝修改远程的操作,返回提供商特定的撤销提示;Agent必须将这些提示告知用户,而非尝试静默回滚远程操作)gg
Navigation tools
导航工具
- — jump to a commit by position, GG-ID, or SHA
stack_move - — move first/last/prev/next in the stack
stack_navigate
- —— 通过位置、GG-ID或SHA跳转到指定提交
stack_move - —— 在堆叠中跳转到第一个/最后一个/上一个/下一个提交
stack_navigate
Agent guidelines for MCP
Agent使用MCP的指南
- Prefer read-only tools to understand state before writing.
- Use with
stack_syncfor new PRs unless the user asks for non-draft. Note:draft: trueonly affects newly created PRs, not existing ones.draft: true - Never call without explicit user approval.
stack_land - Parse JSON output from ,
stack_sync,stack_land, andstack_clean.stack_lint - If shows
stack_status, runbehind_base > 0before syncing.stack_rebase - Rewrite tools (,
stack_squash,stack_absorb,stack_reorder,stack_split,stack_drop, plus CLIstack_rebase) will fail withgg unstackwhen a target commit is merged or already on the base branch. Each tool accepts aImmutableTargetsparameter that maps toforce: bool/--force. Only set--ignore-immutableafter surfacing the affected commits to the user and getting explicit approval.force: truealways passesstack_drop(MCP is non-interactive), but its--yesparam is separate from the confirmation-skip — leave itforce: boolunless the user has approved rewriting merged/base commits.false
- 优先使用只读工具了解状态,再执行写入操作。
- 除非用户要求非草稿,否则使用时设置
stack_sync创建新PR。注意:draft: true仅影响新创建的PR,不影响现有PR。draft: true - 绝不要在未获得用户明确批准的情况下调用。
stack_land - 解析、
stack_sync、stack_land和stack_clean的JSON输出。stack_lint - 如果显示
stack_status,请在同步前运行behind_base > 0。stack_rebase - 重写工具(、
stack_squash、stack_absorb、stack_reorder、stack_split、stack_drop,以及CLI命令stack_rebase)在目标提交已合并或已在基础分支上时,会因gg unstack错误失败。每个工具都接受ImmutableTargets参数,对应force: bool/--force。仅在向用户列出受影响的提交并获得明确批准后,才设置--ignore-immutable。force: true始终传递stack_drop(MCP为非交互式),但其--yes参数与跳过确认是分开的——除非用户已批准重写已合并/基础提交,否则请保持force: bool。false