jj-hunk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesejj-hunk
jj-hunk
Programmatic hunk selection for Jujutsu. Split, commit, or squash specific hunks without interactive prompts.
面向Jujutsu的程序化代码块选择工具。无需交互式提示即可拆分、提交或合并特定代码块。
Basic Workflow
基础工作流
List available hunks, create a spec file, then apply:
bash
undefined列出可用代码块,创建规格文件,然后执行操作:
bash
undefinedSee what hunks exist
查看现有代码块
jj-hunk list
jj-hunk list --format text # Human-readable output
jj-hunk list --files # Files with hunk counts only
jj-hunk list
jj-hunk list --format text # 人类可读格式输出
jj-hunk list --files # 仅显示包含代码块的文件及数量
Split changes using a spec file
使用规格文件拆分变更
jj-hunk split --spec-file /tmp/spec.yaml "feat: add feature A"
jj-hunk split --spec-file /tmp/spec.yaml "feat: add feature A"
Commit specific files, leave rest uncommitted
提交特定文件,其余变更保留为未提交状态
jj-hunk commit --spec-file /tmp/commit-spec.yaml "fix: handle edge case"
jj-hunk commit --spec-file /tmp/commit-spec.yaml "fix: handle edge case"
Squash into parent
合并到父提交
jj-hunk squash --spec-file /tmp/squash-spec.yaml
Targets any revision with `-r <rev>` (default is `@` for working copy). Read specs from stdin with `-`.jj-hunk squash --spec-file /tmp/squash-spec.yaml
可通过 `-r <rev>` 指定目标版本(默认是工作副本 `@`)。使用 `-` 从标准输入读取规格。Spec Format
规格文件格式
YAML files control which hunks to keep or reset:
yaml
files:
src/main.rs:
hunks: [0, "hunk-7c3d..."] # Select by index or stable id
path/to/skip:
action: reset # Discard all changes
default: reset # Unlisted files get this action- — select by 0-based index or stable id from
hunks: [indices|ids]jj-hunk list - — select by id string (sha256-based, stable across runs)
ids: ["hunk-..."] - /
action: keep— keep or discard all changes in a fileaction: reset - — action for unlisted files
default
Use to generate an ID-based starting spec. IDs are more reliable than indices since they're stable across runs.
jj-hunk list --spec-templateYAML文件用于控制保留或重置哪些代码块:
yaml
files:
src/main.rs:
hunks: [0, "hunk-7c3d..."] # 通过索引或稳定ID选择
path/to/skip:
action: reset # 丢弃所有变更
default: reset # 未列出的文件执行此操作- — 通过0-based索引或
hunks: [indices|ids]输出的稳定ID选择jj-hunk list - — 通过ID字符串选择(基于sha256,跨运行稳定)
ids: ["hunk-..."] - /
action: keep— 保留或丢弃文件中的所有变更action: reset - — 未列出文件的默认操作
default
使用 生成基于ID的初始规格文件。相比索引,ID更可靠,因为它们在多次运行中保持稳定。
jj-hunk list --spec-templateExample: Split by Hunk
示例:按代码块拆分
bash
undefinedbash
undefined1. List hunks
1. 列出代码块
jj-hunk list --format text
jj-hunk list --format text
Output: M src/main.rs — hunk 0 insert hunk-abc123, hunk 1 insert hunk-def456
输出:M src/main.rs — hunk 0 insert hunk-abc123, hunk 1 insert hunk-def456
2. Create spec for first hunk only
2. 创建仅包含第一个代码块的规格文件
cat > /tmp/split-spec.yaml << 'EOF'
files:
src/main.rs:
hunks: [0]
default: reset
EOF
cat > /tmp/split-spec.yaml << 'EOF'
files:
src/main.rs:
hunks: [0]
default: reset
EOF
3. Split — first hunk becomes commit A, rest stays in working copy
3. 拆分操作 — 第一个代码块成为提交A,其余变更保留在工作副本中
jj-hunk split --spec-file /tmp/split-spec.yaml "feat: add feature A"
undefinedjj-hunk split --spec-file /tmp/split-spec.yaml "feat: add feature A"
undefinedExample: Commit Subset of Changes
示例:提交部分变更
bash
cat > /tmp/commit-spec.yaml << 'EOF'
files:
src/fix.rs:
action: keep
default: reset
EOF
jj-hunk commit --spec-file /tmp/commit-spec.yaml "fix: handle edge case"bash
cat > /tmp/commit-spec.yaml << 'EOF'
files:
src/fix.rs:
action: keep
default: reset
EOF
jj-hunk commit --spec-file /tmp/commit-spec.yaml "fix: handle edge case"Tips
小贴士
- IDs are stable (sha256-based), indices are not — prefer ids for reproducibility
- Use for a quick summary without full hunk details
--files - Read spec from stdin:
cat spec.yaml | jj-hunk commit - "message" - Use with split/squash to target any revision
-r <rev> - When verifying after operations, always use the original change ID — see jj-core skill for template syntax (,
concat()field)description
- ID是稳定的(基于sha256),索引则不是——为了可重复性优先使用ID
- 使用 快速获取摘要,无需查看完整代码块详情
--files - 从标准输入读取规格:
cat spec.yaml | jj-hunk commit - "message" - 使用 配合split/squash操作指定目标版本
-r <rev> - 操作后验证时,请始终使用原始变更ID——查看jj-core技能了解模板语法(、
concat()字段)description