教程

提示: 本教程内容已经有些过时。很多人更喜欢 Steve Klabnik 的替代教程,虽然它尚未完成。

本教程假设读者已经熟悉 Git。

准备工作

如果你还没有安装,请先完成 Jujutsu 的安装与配置

克隆一个 Git 仓库

提示: 本教程中使用的大多数 ID 在你本地实践时会有所不同!

我们先用 jj 来克隆 GitHub 上的 Hello-World 仓库:

  1. # 注意 "clone" 前的 "git"(目前尚不支持克隆原生的 jj 仓库)
  2. $ jj git clone https://github.com/octocat/Hello-World
  3. Fetching into new repo in "/tmp/tmp.O1DWMiaKd4/Hello-World"
  4. remote: Enumerating objects: 13, done.
  5. remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13 (from 1)
  6. bookmark: master@origin [new] untracked
  7. bookmark: octocat-patch-1@origin [new] untracked
  8. bookmark: test@origin [new] untracked
  9. Setting the revset alias `trunk()` to `master@origin`
  10. Working copy (@) now at: kntqzsqt d7439b06 (empty) (no description set)
  11. Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
  12. Added 1 files, modified 0 files, removed 0 files
  13. $ cd Hello-World

此时运行 jj st(即 jj status 的缩写),你会看到类似的输出:

  1. $ jj st
  2. The working copy has no changes.
  3. Working copy (@) : kntqzsqt d7439b06 (empty) (no description set)
  4. Parent commit (@-): orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1

我们来分析下这个输出,里面介绍了几个新概念。你会看到两个提交:父提交(Parent)和工作副本(Working copy)。它们各自有两个不同的标识符:一个是 change ID(变更 ID),另一个是 commit ID(提交 ID)。

比如,父提交的 change ID 是 orrkosyo,而 commit ID 是 7fd1a60b

Git 用户注意: 这个 commit ID(或称 hash)和你在 Git 中看到的是一样的。如果你在一个 Git 仓库中运行 git log,应该能看到相同的提交 ID。 而 change ID 是 Jujutsu 中引入的新概念,Git 中没有这个概念。

我们也可以从输出中看到,工作副本本身就是一个提交,它有自己的 commit ID(比如示例中的 d7439b06)。当你对工作副本做出修改时,下一次运行 jj 命令时,它会自动修改(amend)当前的工作副本提交。

Git 用户注意: 这是 Jujutsu 与 Git 的一个重要区别。在 Git 中,工作副本不是一个提交;但在 Jujutsu 中,它是。