Intermezzo: A Taste Of a Fanciful Workflow
Indulge me in a little digression.
Why would anyone ever need to create a commit in the middle of an existing branch? Whatever the use case, how frequent can this possibly be?
I'm happy you asked! This is the basis of some interesting workflows you might eventually love. Here's an example. You will experiment with similar ideas in detail in a separate chapter.
Say you have 3 local branches:
@ u Z
○ tn Y
○ tl X
○ y W
│
│ ○ n C
│ ○ q B
│ ○ k A
├─╯
│ ○ m Work C
│ ○ l Work B
│ ○ p Work A
├─╯
○ o
◆ z
You want to know how they work together. They'll eventually be merged
by CI/CD, but why wait? Merge them locally now. After all, you can
always delete the merge commit with jj abandon in a breeze. Without
further ado, here's the Change x, merging the 3 branches together:
@ kx
○ x Megamerge
├─┬─╮
│ │ ○ u Z
│ │ ○ tn Y
│ │ ○ tl X
│ │ ○ y W
│ ○ │ m Work C
│ ○ │ l Work B
│ ○ │ p Work A
│ ├─╯
○ │ n C
○ │ q B
○ │ kt A
├─╯
○ o
◆ z
You might be wondering: how did I create that merge commit
x, if there's nojj mergecommand?
Believe it or not, you actually already have all the ingredients to figure it out. Think about it. You'll read the answer to this quiz in two pages.
Now, say you have to work on the feature A-B-C. Why don't you
work from the megamerge, so you immediately make sure the feature
A-B-C works well with the other 2?
So, do your work in kx. When you are done, you add a new empty
Change on top of A-B-C:
@ kx
○ x Megamerge
├─┬─╮
│ │ ○ u Z
│ │ ○ tn Y
│ │ ○ tl X
│ │ ○ y W
│ ○ │ m Work 2
│ ○ │ l Work 2
│ ○ │ p Work 1
│ ├─╯
○ │ s D <--- new Change
○ │ n C
○ │ q B
○ │ kt A
├─╯
○ o
◆ z
and then you send your work from kz back to that newly created empty
commit s, using jj squash -t s (you'll learn it).
Sounds insane? Yes, it is! I was also shocked the first time I found out it's a popular workflow. Honestly, it didn't take long before it felt more useful than weird. Now it's my daily driver.
You might even find it convenient yourself.
Let's go ahead, you are very close to learning it all.