Jujutsu (jj) Version Control System
Jujutsu (jj) 版本控制系统
This skill helps you work with Jujutsu, a Git-compatible VCS with mutable commits and automatic rebasing.
Tested with jj v0.37.0 - Commands may differ in other versions.
本技能可帮助你使用Jujutsu(jj),这是一款与Git兼容的版本控制系统,支持可变提交和自动变基。
已在jj v0.37.0版本测试——其他版本的命令可能有所不同。
Important: Automated/Agent Environment
重要提示:自动化/Agent环境
When running as an agent:
- Always use flags to provide messages inline rather than relying on editor prompts:
在Agent环境中运行时:
- 始终使用参数,直接在命令行提供消息,而非依赖编辑器弹窗:
Always use -m to avoid editor prompts
始终使用-m以避免编辑器弹窗
jj desc -m "message" # NOT: jj desc
jj squash -m "message" # NOT: jj squash (which opens editor)
Editor-based commands will fail in non-interactive environments.
2. **Verify operations with `jj st`** after mutations (`squash`, `abandon`, `rebase`, `restore`) to confirm the operation succeeded.
jj desc -m "message" # 不要使用:jj desc
jj squash -m "message" # 不要使用:jj squash(会打开编辑器)
基于编辑器的命令在非交互式环境中会执行失败。
2. **在执行变更操作(`squash`、`abandon`、`rebase`、`restore`)后,使用`jj st`验证操作结果**,确认操作已成功完成。
The Working Copy is a Commit
工作副本即提交
In jj, your working directory is always a commit (referenced as
). Changes are automatically snapshotted when you run any jj command. There is no staging area.
There is no need to run
.
在jj中,你的工作目录始终是一个提交(用
引用)。当你运行任何jj命令时,变更会被自动快照保存。jj没有暂存区。
Commits Are Mutable
提交是可变的
CRITICAL: Unlike git, jj commits can be freely modified. This enables a high-quality commit workflow:
- Use to initialize a new, blank commit.
- Describe your intended changes first with
- Make your changes
- When complete, use to initialize a new, blank commit and begin the process again.
You may refine the commit using
or
as needed
关键提示:与Git不同,jj的提交可自由修改。这实现了高质量的提交工作流:
- 使用初始化一个新的空白提交。
- 先用描述你计划的变更
- 进行代码修改
- 完成后,使用初始化一个新的空白提交,重复上述流程。
Change IDs vs Commit IDs
变更ID vs 提交ID
- Change ID: A stable identifier (like ) that persists when a commit is rewritten
- Commit ID: A content hash (like ) that changes when commit content changes
Prefer using Change IDs when referencing commits in commands.
- 变更ID:稳定的标识符(如),在提交被重写时仍保持不变
- 提交ID:内容哈希值(如),当提交内容变更时会随之改变
在命令中引用提交时,优先使用变更ID。
Starting Work: Describe First, Then Code
开始工作:先描述,再编码
Always create your commit message before writing code:
First, describe what you intend to do
首先,描述你要完成的工作
jj desc -m "Add user authentication to login endpoint"
Then make your changes - they automatically become part of this commit
然后进行修改——变更会自动成为该提交的一部分
... edit files ...
... 编辑文件 ...
Creating Atomic Commits
创建原子提交
Each commit should represent ONE logical change. Use this format for commit messages:
Examples:
- "Add validation to user input forms"
- "Fix null pointer in payment processor"
- "Remove deprecated API endpoints"
- "Update dependencies to latest versions"
每个提交应代表一个逻辑变更。提交信息请使用以下格式:
示例:
- "为用户输入表单添加验证"
- "修复支付处理器中的空指针问题"
- "移除已废弃的API端点"
- "将依赖更新至最新版本"
View recent commits
查看近期提交
View with patches
查看带补丁的历史
View specific commit
查看特定提交
View diff of working copy
查看工作副本的差异
Moving Between Commits
在提交间切换
Create a new empty commit on top of current
在当前提交之上创建一个新的空提交
Create new commit with message
创建带消息的新提交
jj new && jj desc -m "Commit message"
jj new && jj desc -m "Commit message"
Edit an existing commit (working copy becomes that commit)
编辑现有提交(工作副本会切换为该提交)
Edit the previous commit
编辑上一个提交
Edit the next commit
编辑下一个提交
Move changes from current commit into its parent:
Squash all changes into parent
将所有变更合并到父提交
jj squash
**Note**: `jj squash -i` opens an interactive UI and will hang in agent environments. Avoid it.
jj squash
**注意**:`jj squash -i`会打开交互式界面,在Agent环境中会挂起,请避免使用。
Warning:
is interactive and will hang in agent environments. To divide a commit, use
to move changes out, then create separate commits manually.
警告:
是交互式命令,在Agent环境中会挂起。如需拆分提交,请使用
将变更移出,然后手动创建独立的提交。
Automatically distribute changes to the commits that last modified those lines:
Absorb working copy changes into appropriate ancestor commits
将工作副本的变更自动分配到合适的祖先提交
Remove a commit entirely (descendants are rebased to its parent):
bash
jj abandon <change-id>
完全移除一个提交(其后代会被变基到其父提交):
bash
jj abandon <change-id>
Reverse the last jj operation:
This reverts the repository to its state before the previous command. Useful for recovering from mistakes like accidental
,
, or
.
撤销上一次jj操作:
这会将版本库恢复到执行上一个命令前的状态。适用于从意外的
、
或
操作中恢复。
Discard changes to specific files or restore files from another revision:
Discard all uncommitted changes in working copy (restore from parent)
丢弃工作副本中所有未提交的变更(从父提交恢复)
Discard changes to specific files
丢弃特定文件的变更
jj restore path/to/file.txt
jj restore path/to/file.txt
Restore files from a specific revision
从特定版本恢复文件
jj restore --from <change-id> path/to/file.txt
jj restore --from <change-id> path/to/file.txt
Working with Bookmarks (Branches)
使用书签(分支)
Bookmarks are jj's equivalent to git branches:
Create a bookmark at current commit
在当前提交创建书签
jj bookmark create my-feature -r@
jj bookmark create my-feature -r@
Move bookmark to a different commit
将书签移动到另一个提交
jj bookmark move my-feature --to <change-id>
jj bookmark move my-feature --to <change-id>
jj bookmark delete my-feature
jj bookmark delete my-feature
Working with Existing Git Repos
处理现有Git版本库
Clone a git repository
克隆Git版本库
Initialize jj in an existing git repo
在现有Git版本库中初始化jj
Switching Between jj and git (Colocated Repos)
在jj和Git间切换(共存版本库)
In a colocated repository (where both
and
exist), you can use both jj and git commands. However, there are important considerations:
Switching to git mode (e.g., for merge workflows):
在共存版本库中(同时存在
和
目录),你可以同时使用jj和Git命令,但有一些重要注意事项:
切换到Git模式(例如用于合并工作流):
First, ensure your jj working copy is clean
首先,确保jj工作副本是干净的
Then checkout a branch with git
然后用Git检出分支
git checkout <branch-name>
**Switching back to jj mode**:
```bash
git checkout <branch-name>
Use jj edit to resume working with jj
使用jj edit恢复jj工作
jj edit <change-id>
**Important notes:**
- Git may complain about uncommitted changes if jj's working copy differs from the git HEAD
- ALWAYS ensure your work is committed in jj before switching to git
- After git operations, jj will detect and incorporate the changes on next command
jj edit <change-id>
**重要说明**:
- 如果jj工作副本与Git HEAD不一致,Git可能会提示存在未提交的变更
- **切换到Git前,务必确保所有工作已在jj中提交**
- 执行Git操作后,jj会在下次命令执行时检测并合并这些变更
When the user asks you to push changes:
Push a specific bookmark to the remote
将特定书签推送到远程
jj git push -b <bookmark-name>
jj git push -b <bookmark-name>
Example: push the main bookmark
示例:推送main书签
jj git push -b main
**Before pushing, ensure:**
1. Your bookmark points to the correct commit (bookmarks don't auto-advance like git branches)
2. The commits are refined and atomic
3. The user has explicitly requested the push
**IMPORTANT**: Unlike git branches, jj bookmarks do not automatically move when you create new commits. You must manually update them before pushing:
```bash
jj git push -b main
**推送前请确认**:
1. 你的书签指向正确的提交(书签不会像Git分支那样自动推进)
2. 提交已优化且是原子化的
3. 用户已明确要求推送
**重要提示**:与Git分支不同,jj书签不会在你创建新提交时自动移动。推送前你必须手动更新书签:
```bash
Move an existing bookmark to the current commit
将现有书签移动到当前提交
jj bookmark move my-feature --to @
jj bookmark move my-feature --to @
jj git push -b my-feature
If no bookmark exists for your changes, create one first:
```bash
jj git push -b my-feature
如果你的变更没有对应的书签,请先创建一个:
```bash
Create a bookmark at the current commit
在当前提交创建书签
jj bookmark create my-feature
jj bookmark create my-feature
jj git push -b my-feature
jj git push -b my-feature
jj allows committing conflicts — you can resolve them later:
jj st
**Agent conflict resolution**: Do not use `jj resolve` (interactive). Instead, edit the conflicted files directly to remove conflict markers, then run `jj st` to verify resolution.
jj st
**Agent冲突解决**:不要使用`jj resolve`(交互式命令)。请直接编辑冲突文件以移除冲突标记,然后运行`jj st`验证是否已解决。
Preserving Commit Quality
保持提交质量
IMPORTANT: Because commits are mutable, always refine them:
- Review your commit: or
- Is it atomic? One logical change per commit
- Is the message clear? Use imperative verb phrase in sentence case format with no full stop: "Verb object"
- Are there unrelated changes? Use to move changes out, then create separate commits
- Should changes be elsewhere? Use or
重要提示:由于提交是可变的,请始终优化你的提交:
- 检查提交:使用或
- **是否原子化?**每个提交对应一个逻辑变更
- **消息是否清晰?**使用祈使句短语,首字母大写,无句号:"动词+对象"
- **是否存在无关变更?**使用将变更移出,然后创建独立提交
- **变更是否应该放在其他提交?**使用或
| Action | Command |
|---|
| Describe commit | |
| View status | |
| View log | |
| View diff | |
| New commit | jj new && jj desc -m "message"
|
| Edit commit | |
| Squash to parent | |
| Auto-distribute | |
| Abandon commit | |
| Undo last operation | |
| Restore files | |
| Create bookmark | jj bookmark create <name>
|
| Push bookmark | |
| 操作 | 命令 |
|---|
| 描述提交 | |
| 查看状态 | |
| 查看历史 | |
| 查看差异 | |
| 新建提交 | jj new && jj desc -m "message"
|
| 编辑提交 | |
| 合并到父提交 | |
| 自动分配变更 | |
| 废弃提交 | |
| 撤销上一次操作 | |
| 恢复文件 | |
| 创建书签 | jj bookmark create <name>
|
| 推送书签 | |
Best Practices Summary
最佳实践总结
- Describe first: Set the commit message before coding
- One change per commit: Keep commits atomic and focused
- Use change IDs: They're stable across rewrites
- Refine commits: Leverage mutability for clean history
- Embrace the workflow: No staging area, no stashing - just commits
- 先描述:编写代码前设置提交信息
- 每个提交对应一个变更:保持提交原子化且聚焦
- 使用变更ID:它们在重写后仍保持稳定
- 优化提交:利用可变性实现清晰的历史记录
- 遵循工作流:没有暂存区,无需暂存——只需提交