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 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 the conflicting files are about a different feature (authentication) and have nothing to do with this branch.

Solution

Move the conflicts elsewhere, separating the conflict-free PDF generation from authentication.

There are several ways.

With jj squash

  • Create a Change elsewhere (e.g., on top of a) to hold the conflicts:
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. You can do jj new and jj squash in one step using jj squash -o a (which creates a new Change on top of a):

jj squash -f d -o a authentication.ts

With jj split

  • Split the conflicted Change in two:
jj split -r d -m "authentication"
  • Select all unrelated changes for authentication.ts. Keep the PDF generation changes aside.

  • jj split creates a new Change containing only the unrelated changes (and thus the conflicts):

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