jujutsu

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Jujutsu (jj) Version Control Skill

Jujutsu (jj) 版本控制技能

This skill enables working with Jujutsu, a Git-compatible version control system with a fundamentally different model. Jujutsu treats the working copy as a commit, has no staging area, and uses change IDs for stable references across rewrites.
本技能支持使用Jujutsu——一款与Git兼容但核心模型截然不同的版本控制系统。Jujutsu将工作副本视为提交,没有暂存区,并使用变更ID(Change ID)在重写操作中保持稳定引用。

Core Concepts

核心概念

Working Copy as a Commit

工作副本即提交

Unlike Git, the working copy IS a commit. Changes are automatically snapshotted when running
jj
commands - no explicit
add
or staging required.
与Git不同,Jujutsu的工作副本本身就是一个提交。执行
jj
命令时会自动快照变更——无需显式执行
add
或暂存操作。

Change IDs vs Commit IDs

变更ID vs 提交ID

Every commit has two identifiers:
  • Change ID: Stable across rewrites (e.g.,
    kkmpptxz
    )
  • Commit ID: Hash-based, changes on rewrite (e.g.,
    abc123def
    )
Use change IDs for references that survive rebases.
每个提交都有两个标识符:
  • 变更ID(Change ID):在重写操作中保持稳定(例如:
    kkmpptxz
  • 提交ID(Commit ID):基于哈希值,重写时会变化(例如:
    abc123def
使用变更ID作为能在变基后保留的引用。

Revsets

版本集(Revsets)

Revsets are expressions to select commits:
  • @
    - Working copy commit
  • @-
    - Parent of working copy
  • root()
    - Repository root
  • bookmarks()
    - All bookmarked commits
  • foo..bar
    - Commits from foo to bar (exclusive)
  • foo::bar
    - Commits from foo to bar (inclusive)
  • A | B
    - Union
  • A & B
    - Intersection
  • ~A
    - Complement
版本集是用于选择提交的表达式:
  • @
    - 工作副本提交
  • @-
    - 工作副本的父提交
  • root()
    - 仓库根提交
  • bookmarks()
    - 所有带书签的提交
  • foo..bar
    - 从foo到bar的提交(不包含foo)
  • foo::bar
    - 从foo到bar的提交(包含foo和bar)
  • A | B
    - 并集
  • A & B
    - 交集
  • ~A
    - 补集

Bookmarks (not Branches)

书签(Bookmarks,而非分支)

Bookmarks are named pointers that map to Git branches. They move automatically when commits are rewritten.
书签是命名指针,与Git分支相对应。当提交被重写时,书签会自动移动。

Quick Reference

快速参考

Git CommandJujutsu EquivalentNotes
git init
jj git init
Use
--colocate
for Git interop
git clone URL
jj git clone URL
Git repos only
git status
jj st
Shows working copy diff
git diff
jj diff
Diff of working copy
git diff --staged
N/ANo staging area
git add && git commit
jj commit
Auto-includes all changes
git commit --amend
jj squash
Squash into parent
git log --oneline --graph
jj log
Visual commit graph
git show COMMIT
jj show REV
Show revision details
git checkout -b NAME
jj new
Start new change
git switch BRANCH
jj edit BOOKMARK
Edit existing change
git reset --hard
jj abandon
Discard working copy
git stash
jj new
Just start new change
git rebase B A
jj rebase -b A -d B
Rebase A onto B
git cherry-pick
jj duplicate
Copy commits
git merge
jj new A B
Creates merge commit
git fetch
jj git fetch
Fetch from remote
git push
jj git push
Push bookmarks
git branch NAME
jj bookmark create NAME
Create bookmark
Git 命令Jujutsu 等效命令说明
git init
jj git init
使用
--colocate
实现Git互操作
git clone URL
jj git clone URL
仅支持Git仓库
git status
jj st
显示工作副本差异
git diff
jj diff
工作副本的差异对比
git diff --staged
N/A无暂存区
git add && git commit
jj commit
自动包含所有变更
git commit --amend
jj squash
合并到父提交中
git log --oneline --graph
jj log
可视化提交图谱
git show COMMIT
jj show REV
显示版本详情
git checkout -b NAME
jj new
创建新变更
git switch BRANCH
jj edit BOOKMARK
编辑现有变更
git reset --hard
jj abandon
丢弃工作副本
git stash
jj new
直接创建新变更即可
git rebase B A
jj rebase -b A -d B
将A变基到B上
git cherry-pick
jj duplicate
复制提交
git merge
jj new A B
创建合并提交
git fetch
jj git fetch
从远程仓库拉取
git push
jj git push
推送书签
git branch NAME
jj bookmark create NAME
创建书签

Common Workflows

常见工作流

Starting Work

开始工作

bash
undefined
bash
undefined

Clone a repo

克隆仓库

Or init in existing directory

或在现有目录中初始化

jj git init --colocate
jj git init --colocate

Create new change from main

从main分支创建新变更

jj new main
jj new main

Work on files (no add needed)

处理文件(无需add操作)

Edit files...

编辑文件...

Describe the change

描述变更

jj describe -m "feat: add new feature"
jj describe -m "feat: add new feature"

Finish and start next change

完成当前变更并开始下一个

jj new
undefined
jj new
undefined

Viewing State

查看状态

bash
undefined
bash
undefined

Show log with graph

显示带图谱的提交日志

jj log
jj log

Show working copy diff

显示工作副本差异

jj diff
jj diff

Show specific revision

显示特定版本

jj show @-
jj show @-

Status of working copy

工作副本状态

jj st
jj st

Show file at revision

查看指定版本的文件

jj file show path/to/file -r REV
undefined
jj file show path/to/file -r REV
undefined

Modifying History

修改历史

bash
undefined
bash
undefined

Squash working copy into parent

将工作副本合并到父提交

jj squash
jj squash

Squash specific change into parent

将特定变更合并到父提交

jj squash -r CHANGE
jj squash -r CHANGE

Interactive squash (select hunks)

交互式合并(选择代码块)

jj squash -i
jj squash -i

Split a commit

拆分提交

jj split
jj split

Edit a commit message

编辑提交信息

jj describe -r REV -m "new message"
jj describe -r REV -m "new message"

Edit an older commit

编辑旧提交

jj edit CHANGE
jj edit CHANGE

Make changes...

进行修改...

jj new # Return to tip
undefined
jj new # 返回最新提交
undefined

Rebasing

变基

bash
undefined
bash
undefined

Rebase current change onto main

将当前变更变基到main分支

jj rebase -d main
jj rebase -d main

Rebase branch onto main

将分支变基到main分支

jj rebase -b BRANCH -d main
jj rebase -b BRANCH -d main

Rebase revision and descendants

将指定版本及其后代变基

jj rebase -r REV -d DEST
jj rebase -r REV -d DEST

Rebase source and descendants

将源版本及其后代变基

jj rebase -s SOURCE -d DEST
undefined
jj rebase -s SOURCE -d DEST
undefined

Bookmarks and Remotes

书签与远程仓库

bash
undefined
bash
undefined

Create bookmark at current change

在当前变更创建书签

jj bookmark create NAME
jj bookmark create NAME

Create bookmark at specific revision

在指定版本创建书签

jj bookmark create NAME -r REV
jj bookmark create NAME -r REV

Move bookmark

移动书签

jj bookmark move NAME -r REV
jj bookmark move NAME -r REV

List bookmarks

列出所有书签

jj bookmark list
jj bookmark list

Track remote bookmark

跟踪远程书签

jj bookmark track NAME@origin
jj bookmark track NAME@origin

Push bookmark to remote

将书签推送到远程仓库

jj git push --bookmark NAME
jj git push --bookmark NAME

Push all bookmarks

推送所有书签

jj git push --all
jj git push --all

Fetch from remote

从远程仓库拉取

jj git fetch
undefined
jj git fetch
undefined

Working with GitHub

与GitHub协作

bash
undefined
bash
undefined

Create PR branch

创建PR分支

jj new main
jj new main

Work...

进行开发...

jj describe -m "feat: my feature" jj bookmark create my-feature jj git push --bookmark my-feature
jj describe -m "feat: my feature" jj bookmark create my-feature jj git push --bookmark my-feature

Update PR after review

评审后更新PR

jj edit my-feature
jj edit my-feature

Make changes...

进行修改...

jj git push --bookmark my-feature
jj git push --bookmark my-feature

After merge, clean up

合并后清理

jj git fetch jj bookmark delete my-feature
undefined
jj git fetch jj bookmark delete my-feature
undefined

Conflict Resolution

冲突解决

Conflicts in Jujutsu don't block rebases - they're recorded in commits.
bash
undefined
Jujutsu中的冲突不会阻止变基——冲突会被记录在提交中。
bash
undefined

Check for conflicts

检查冲突

jj log # Conflicted commits shown with marker
jj log # 冲突提交会带有标记显示

Resolve conflicts

解决冲突

jj new CONFLICTED_CHANGE
jj new CONFLICTED_CHANGE

Edit conflict markers in files

编辑文件中的冲突标记

jj squash # Squash resolution into conflicted change
jj squash # 将解决方案合并到冲突提交中

Or use resolve command

或使用resolve命令

jj resolve
undefined
jj resolve
undefined

Undo Operations

撤销操作

bash
undefined
bash
undefined

View operation log

查看操作日志

jj op log
jj op log

Undo last operation

撤销上一次操作

jj undo
jj undo

Restore to specific operation

恢复到指定操作状态

jj op restore OP_ID
undefined
jj op restore OP_ID
undefined

Key Differences from Git

与Git的主要差异

  1. No staging area: All file changes automatically included
  2. Working copy is a commit: Always have a "draft" commit
  3. Conflicts don't block: Rebases complete, conflicts recorded
  4. Change IDs: Stable references across history rewrites
  5. Operation log: Full undo capability for any operation
  6. Automatic snapshot: No risk of losing uncommitted work
  1. 无暂存区:所有文件变更会自动被包含
  2. 工作副本即提交:始终存在一个“草稿”提交
  3. 冲突不阻塞:变基会完成,冲突被记录下来
  4. 变更ID:在历史重写中保持稳定的引用
  5. 操作日志:支持对任何操作进行完全撤销
  6. 自动快照:不会丢失未提交的工作内容

Colocated vs Non-colocated

共存模式(Colocated)与非共存模式

Colocated (
jj git init --colocate
):
  • .git
    and
    .jj
    in same directory
  • Can use Git tools alongside jj
  • Git sees jj commits
Non-colocated (
jj git init
):
  • Only
    .jj
    directory
  • Pure jj workflow
  • Use
    jj git export
    to sync to Git
共存模式
jj git init --colocate
):
  • .git
    .jj
    目录在同一位置
  • 可同时使用Git工具和jj
  • Git可以识别jj的提交
非共存模式
jj git init
):
  • 仅存在
    .jj
    目录
  • 纯jj工作流
  • 使用
    jj git export
    同步到Git

Additional Resources

额外资源

Reference Files

参考文档

For detailed command reference and advanced workflows:
  • references/git-command-table.md
    - Complete Git to Jujutsu command mapping
  • references/revsets.md
    - Revset syntax and examples
如需详细命令参考和高级工作流:
  • references/git-command-table.md
    - 完整的Git与Jujutsu命令映射
  • references/revsets.md
    - 版本集语法及示例

External Documentation

外部文档