jjc: Non-interactive hunk-level operations for Jujutsu

jjc: Non-interactive hunk-level operations for Jujutsu

jjc:Jujutsu 的非交互式代码块(Hunk)操作工具

jjc is a scriptable alternative to jj split’s interactive mode. It requires jj v0.41.0. jjc 是 jj split 交互模式的可脚本化替代方案。它需要 jj v0.41.0 版本。

Install

安装

cargo install --git https://tangled.sh/akashina.tngl.sh/jjc
# or from local checkout:
# 或从本地检出安装:
cargo install --path .

Commands

命令

jjc hunks — list hunks jjc hunks — 列出代码块

  • jjc hunks # list all hunks in @ (列出 @ 处的所有代码块)
  • jjc hunks -r main # list hunks in a specific revision (列出特定修订版本中的代码块)
  • jjc hunks abc123 # inspect a single hunk (by ID or prefix) (检查单个代码块,通过 ID 或前缀)
  • jjc hunks --full # include numbered diff lines (包含带行号的差异行)
  • jjc hunks --blame # annotate each line with originating commit (为每一行标注原始提交信息)

Default output shows a changed-lines preview (up to 4 lines): 默认输出显示更改行的预览(最多 4 行):

a1b[2c3d4e5f6] src/main.rs (+3 -1)
+ println!("new line");
- old_call();

f09[8a7b6c5d4e] src/lib.rs (+1 -0)
+use std::io;

--full adds context lines with line numbers, and lists change atoms when a hunk has more than one: --full 会添加带有行号的上下文行,并在代码块包含多个更改原子(change atoms)时将其列出:

a1b[2c3d4e5f6] src/main.rs (+3 -1)
1: fn main() {
2:+ println!("new line");
3:- old_call();
4: }

a1b[2c3d4e5f6]#1 @2
a1b[2c3d4e5f6]#2 @3

Hunk IDs use bracket-style prefix highlighting (same as jj log): a1b[2c3d4e5f6] means a1b is the shortest unique prefix. 代码块 ID 使用括号样式的前缀高亮(与 jj log 相同):a1b[2c3d4e5f6] 表示 a1b 是最短的唯一前缀。

jjc pick — split hunks into a new commit jjc pick — 将代码块拆分到新提交中

  • jjc pick a1b -m "extract logging" # pick entire hunk (选取整个代码块)
  • jjc pick a1b#2 -m "fix off-by-one" # pick a single change atom (选取单个更改原子)
  • jjc pick a1b@15-20 -m "refactor" # pick by target line range (按目标行范围选取)
  • jjc pick a1b c3d -r foo -m "partial" # pick multiple hunks from revision foo (从修订版本 foo 中选取多个代码块)

Creates a new commit with the selected hunks, then rewrites the source revision on top of it (like jj split but non-interactive). 使用选定的代码块创建一个新提交,然后在该提交之上重写源修订版本(类似于 jj split,但为非交互式)。

jjc drop — revert hunks to parent content jjc drop — 将代码块还原为父级内容

  • jjc drop a1b # drop a hunk from @ (从 @ 中丢弃一个代码块)
  • jjc drop a1b c3d # drop multiple hunks (丢弃多个代码块)

Rewrites the revision in place with selected hunks reverted. Like “Revert Hunk” in a diff editor. 原地重写修订版本并还原选定的代码块。类似于差异编辑器中的“还原代码块(Revert Hunk)”功能。

jjc fold — squash hunks into another revision jjc fold — 将代码块合并到另一个修订版本中

  • jjc fold a1b --into main # fold hunk from @ into main (将 @ 中的代码块合并到 main)
  • jjc fold a1b -r feat --into main # fold from a specific source (从特定源合并)
  • jjc fold --select feat:a1b,c3d # multi-source with explicit assignment (带显式分配的多源合并)

Hunk selectors

代码块选择器

All write commands (pick, drop, fold) accept hunk selectors: 所有写入命令(pickdropfold)都接受代码块选择器:

FormMeaning含义
a1bEntire hunk matching ID prefix a1b匹配 ID 前缀 a1b 的整个代码块
a1b#2Change atom #2 within the hunk代码块内的第 2 个更改原子
a1b@15Lines covering target line 15覆盖目标行 15 的行
a1b@10-20Lines covering target range 10-20覆盖目标范围 10-20 的行

Use jjc hunks to discover IDs and atom indices. 使用 jjc hunks 来查找 ID 和原子索引。

How it works

工作原理

jjc reads the jj repository directly via jj-lib. It loads your jj config (user, repo, workspace layers), snapshots the working copy, and commits transactions with proper descendant rebasing and working copy updates. No jj commands are shelled out or proxied. jjc 通过 jj-lib 直接读取 jj 仓库。它会加载你的 jj 配置(用户、仓库、工作区层级),对工作副本进行快照,并提交带有正确后代变基(rebasing)和工作副本更新的事务。不会调用或代理任何 jj 命令。

Limitations

局限性

  • Only text file hunks are supported.
  • 仅支持文本文件代码块。
  • Binary files, renames, copies, additions, and deletions are listed as unsupported.
  • 二进制文件、重命名、复制、添加和删除操作被列为不支持。
  • Immutable commit checking is minimal (root commit only). Use jj log to verify before rewriting shared history.
  • 不可变提交检查非常有限(仅限根提交)。在重写共享历史记录之前,请使用 jj log 进行验证。
  • .gitignore patterns from git config are not loaded for snapshot; all untracked files are auto-tracked.
  • 快照时不会加载 git 配置中的 .gitignore 模式;所有未追踪的文件都会被自动追踪。