关于 working-with-jj
面向使用 JJ(Jujutsu)版本控制的开发者的参考技能,讲解核心概念、命令、revset、常见问题、辅助脚本和仓库恢复。
主要功能
- 01JJ 概念与常用命令
- 02revset、fileset 和模板说明
- 03常见命令问题与语法提示
- 04描述编辑和检查点脚本
- 05操作日志恢复流程
适用场景
- 01浏览和检查 JJ 修订历史
- 02使用 JJ 表达式筛选修订或文件
- 03撤销操作或恢复仓库状态
- 04批量转换修订描述
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ypares/ agent-skills --skill working-with-jj安装后在 Claude Code 中输入/working-with-jj确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/batch-operations.mdcommand-syntax.mdscripts/jj-batch-descjj-checkpointjj-desc-transformjj-show-desc详细介绍
JJ(Jujutsu)版本控制助手
核心原则
- Change ID(不可变)与 Commit ID(基于内容的哈希,编辑后会变化)
- 操作日志——每项操作都可以撤销(逐步回退:多次执行
jj undo会继续回退,执行jj redo则会反向恢复) - 没有暂存区——工作副本会自动创建快照
- 冲突不会阻塞操作——可以稍后解决
- 提交很轻量——可以自由编辑
- 默认共置——Git 仓库同时包含
.jj和.git(自 v0.34 起) - 三种 DSL:
- revsets:跨修订选择——一个修订(change)ID 是一个简单但完全有效的单元素 revset
- filesets:跨仓库中的文件选择——一个常规文件路径是一个简单但完全有效的单元素 fileset
- templates:选择要记录哪些信息以及如何显示
- 许多 jj 命令需要使用这两种 DSL 中的表达式,以选择要显示或操作的对象
基本命令
jj log -r <revset> [-p] # View history (--patch/-p: include diffs, --count: just count)
jj log -r <revset> -G # -G is short for --no-graph
jj show -r <rev> # Show revision details (description + diff)
jj evolog -r <rev> [-p] # View a revision's evolution
jj new [-A] <base> # Create revision and edit it (-A: insert between <base> and its children rather than just on top of base)
jj new --no-edit <base> # Create without switching
jj edit <rev> # Switch to editing revision
jj desc -r <rev> -m "text" # Set description
jj metaedit -r <rev> -m "text" # Modify metadata (author, timestamps, description)
jj diff # Changes in @
jj diff -r <revset> # Changes in revset (need to be contiguous)
jj diff -f <rev1> -t <rev2> # Differences between two states
jj file show -r <rev> <fileset> # Show file contents at revision (without switching)
jj file show -r <rev> **/*.md -T '"=== " ++ path ++ " ===\n"' # Multiple files with path headers
jj restore <fileset> # Discard changes to files
jj restore --from <commit-id> <fileset> # Restore from another revision/commit
jj split -r <rev> <paths> -m "text" # Split into two revisions
jj absorb # Auto-squash changes into ancestor commits
jj rebase -s <src> -o <dest> # Rebase with descendants onto <dest>
jj rebase -r <rev> -o <dest> # Rebase single revision onto <dest>
# NOTE: -d/--destination is deprecated, use -o/--onto instead
jj file annotate <path> # Blame: who changed each line
jj bisect run -- <cmd> # Binary search for bug-introducing commit
其他命令
jj undo # Undo last operation (progressive - repeat to go further back)
jj redo # Redo undone operation
jj sign -r <rev> # Cryptographically sign commit
jj unsign -r <rev> # Remove signature
jj revert -r <rev> # Create commit that reverts changes (replaces old jj backout)
jj tag set <name> -r <rev> # Create/update local tag
jj tag delete <name> # Delete local tag
jj git colocation enable # Convert to colocated repo
jj git colocation disable # Convert to non-colocated
Revset 速查
@, @-, @-- # Working copy, parent(s), grandparent(s)
::@ # Ancestors
@:: # Descendants
mine() # Your changes
conflicted() # Has conflicts (renamed from conflict() in v0.33)
visible() # Visible revisions (built-in alias)
hidden() # Hidden revisions (built-in alias)
description(substring-i:"text") # Match description (partial, case-insensitive)
subject(substring:"text") # Match first line only
signed() # Cryptographically signed commits
A | B, A & B, A ~ B # Union, intersection, difference
change_id(prefix) # Explicit change ID prefix lookup
parents(x, 2) # Parents with depth
exactly(x, 3) # Assert exactly N revisions
完整的 revset 模式请参阅 references/revsets.md。
常见问题
1. 使用 -r,而不是 --revisions
jj log -r xyz # ✅
jj log --revisions xyz # ❌
2. 并行分支使用 --no-edit
jj new parent -m "A"; jj new -m "B" # ❌ B is child of A!
jj new --no-edit parent -m "A"; jj new --no-edit parent -m "B" # ✅ Both children of parent
3. 在 shell 中为 revset 加引号
jj log -r 'description(substring:"[todo]")' # ✅
4. 使用 -o/--onto,而不是 -d/--destination(v0.36+)
jj rebase -s xyz -o main # ✅ New syntax
jj rebase -s xyz -d main # ⚠️ Deprecated (still works but warns)
5. 符号表达式的限制更严格(v0.32+)
Revset 符号不再解析为多个修订:
jj log -r abc # ❌ Error if 'abc' matches multiple change IDs
jj log -r 'change_id(abc)' # ✅ Explicitly query by prefix
jj log -r 'bookmarks(abc)' # ✅ For bookmark name patterns
6. fileset 中默认使用 glob 模式(v0.36+)
jj diff 'src/*.rs' # Matches glob pattern by default
jj diff 'cwd:"src/*.rs"' # Use cwd: prefix for literal path with special chars
脚本
辅助脚本位于 scripts/。将其添加到 PATH,或直接调用。
| 脚本 | 用途 |
|---|---|
jj-show-desc [REV] | 仅打印完整描述 |
jj-desc-transform <REV> <CMD...> | 将描述通过管道传递给命令 |
jj-batch-desc <SED_FILE> <REV...> | 批量转换描述 |
jj-checkpoint [NAME] | 在执行高风险操作前记录 op ID |
恢复
jj op log # Find operation before problem
jj op restore <op-id> # Restore the WHOLE repository (history included) to that state
参考资料
jj可执行文件内置了详细文档:- 运行
jj help -k bookmarks——了解 JJ 书签、它们与 Git 分支的关系,以及如何从 Git 远程仓库推送和获取书签 - 运行
jj help -k revsets——了解 Revset DSL 语法和模式 - 运行
jj help -k filesets——了解文件路径选择 DSL,即如何让 jj 命令只操作指定文件 - 运行
jj help -k templates——了解模板语言和自定义输出 - 所有 jj 子命令都有相当详细的
--help页面
- 运行
references/command-syntax.md——命令标志详情references/batch-operations.md——对修订描述进行复杂的批量转换
评论
支持 Markdown