Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Move The Conflict Away

Here's an eccentric case: Jujutsu lets you move conflicts around.

Got a conflict on a branch after a rebase? Relocate it elsewhere.

Use Case

  • You just completed a branch about a feature (say, PDF generation):
○  h
○  g
│ ○  f   <- Branch about PDF generation
│ ○  e
│ ○  d   <- Unrelated changes to authentication.ts
│ ○  c
├─╯
○  b
○  a
◆
  • You rebase it on top of h:
$ jj rebase -s c -o h
  • Conflicts.
×  f
×  e
×  d   <- Conflicts in file authentication.ts
○  c
○  h
○  g
○  b
○  a
◆
  • You notice that all the conflicting files belong to a different feature (authentication) and have nothing to do with this branch.

Solution

The idea is to move the conflicts somewhere else, separating PDF generation (which is conflict-free) and authentication.

There are several ways to do that.

With jj squash

  • Create a Change elsewhere (say, on top of a). You will eventually move the conflicts there:
$ jj new -r a -m "authentication"
×  f
×  e
×  d   <- Conflicts in file authentication.ts
○  c
○  h
○  g
○  b
│ ○  x authentication
├─╯
○  a
◆
  • Move the conflicts there:
$ jj squash -f d -t x authentication.ts

○  f
○  e
○  d
○  c
○  h
○  g
○  b
│ ×  x authentication
├─╯
○  a
◆

The file authentication.ts may or may not have conflicts, depending on where you moved it.

jj new followed by jj squash can be done in one step, using jj squash -o a, which will create a new Change on top of a:

jj squash -f d -o a authentication.ts

With jj split

  • You split the conflicted Change in 2
$ jj split -r d -m "authentication"
  • Select all the unrelated changes about authentication.ts. Keep the changes about PDF generation aside.

  • jj split will create a new Change, containing only the unrelated changes (and, therefore, the conflicts):

×  f
×  e
×  d
×  x  authentication
○  c
○  h
○  g
○  b
○  a
◆
  • Move the conflicts away:
jj rebase -r x -o a
○  f
○  e
○  d
○  c
○  h
○  g
○  b
│ ×  x authentication
├─╯
○  a
◆