# 克隆GitHub仓库(注意使用"git clone"而不是"clone") jj git clone https://github.com/octocat/Hello-World Fetching into new repo in"/tmp/tmp.O1DWMiaKd4/Hello-World" remote: Enumerating objects: 13, done. remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13 (from 1) bookmark: master@origin [new] untracked bookmark: octocat-patch-1@origin [new] untracked bookmark: test@origin [new] untracked Setting the revset alias `trunk()` to `master@origin` Working copy (@) now at: kntqzsqt d7439b06 (empty) (no description set) Parent commit (@-) : orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1 Added 1 files, modified 0 files, removed 0 files
# 进入克隆的目录 cd Hello-World
# 查看状态 jj st
初始化新仓库
1 2 3 4 5 6 7 8 9
# 与Git共用仓库(推荐) jj git init --colocate
# 纯jj仓库 jj init
# 配置用户信息 jj config set --user user.name "Adam" jj config set --user user.email "adam@example.com"
注意:纯jj仓库无法被原生Git打开,只有colocate模式才能与Git混合使用。
理解克隆后的状态
克隆后,jj st会显示类似这样的信息:
1 2 3 4
$ jj st The working copy has no changes. Working copy (@) : kntqzsqt d7439b06 (empty) (no description set) Parent commit (@-): orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spaceghost/patch-1
# 创建一系列提交 jj new master -m A; echo a > file1 # Working copy (@) now at: nuvyytnq 00a2aeed (empty) A
jj new -m B1; echo b1 > file1 # Working copy (@) now at: ovknlmro 967d9f9f (empty) B1
jj new -m B2; echo b2 > file1 # Working copy (@) now at: puqltutt 8ebeaffa (empty) B2
jj new -m C; echo c > file2 # Working copy (@) now at: qzvqqupx 62a3c6d3 (empty) C
重基导致冲突
现在将B2直接重基到A上,这会产生冲突:
1 2 3 4 5 6 7 8 9 10 11 12
# 将B2重基到A上(替换为实际的变更ID) jj rebase -s puqltutt -d nuvyytnq
# 输出: # Rebased 2 commits to destination # Working copy (@) now at: qzvqqupx 1978b534 (conflict) C # Parent commit (@-) : puqltutt f7fb5943 (conflict) B2 # Warning: There are unresolved conflicts at these paths: # file1 2-sided conflict # New conflicts appeared in 2 commits: # qzvqqupx 1978b534 (conflict) C # puqltutt f7fb5943 (conflict) B2
解决冲突的步骤
在冲突提交上创建新提交:
1 2
jj new puqltutt # 替换为B2的实际变更ID # Working copy (@) now at: zxoosnnp c7068d1c (conflict) (empty) (no description set)
查看冲突内容:
1 2 3 4 5 6 7 8 9
cat file1 # 输出: # <<<<<<< Conflict 1 of 1 # %%%%%%% Changes from base to side #1 # -b1 # +a # +++++++ Contents of side #2 # b2 # >>>>>>> Conflict 1 of 1 ends
手动解决冲突:
1
echo resolved > file1
检查解决状态:
1 2 3 4 5 6 7
jj st # 输出: # Working copy changes: # M file1 # Working copy (@) : zxoosnnp c2a31a06 (no description set) # Parent commit (@-): puqltutt f7fb5943 (conflict) B2 # Hint: Conflict in parent commit has been resolved in working copy
将解决结果合并到冲突提交:
1 2 3 4 5 6
jj squash # 输出: # Rebased 1 descendant commits # Working copy (@) now at: ntxxqymr e3c279cc (empty) (no description set) # Parent commit (@-) : puqltutt 2c7a658e B2 # Existing conflicts were resolved or abandoned from 2 commits.