Creating a merge commit
Reset your progress
Reset your progress
To reset your progress to the start of this chapter, run the following command:
curl https://jj-for-everyone.github.io/reset.sh | bash -s merge
cd ~/jj-tutorial/repo
I've strung you along for long enough, let's finally create that version with the combined changes.
There are actually two approaches to achieve this, one of them we'll see later. For now, we're going to create a merge commit. As the name implies, a merge commit merges changes from two (or more!) commits.
Until now, we've created new commits with the command jj commit
.
That command actually does two things at once:
It adds a description to the commit you just finished working on and starts a new commit on top of it.
Unfortunately it can't create merge commits.
There is a slightly more "low-level" command for creating new commits called jj new
.
It only creates a new commit and doesn't modify any descriptions.
Importantly, it takes a list of parents as additional arguments.
This allows us to create a commit with two parents, i.e. a merge commit:
jj new main@origin @-
Let's view the result with jj log
:
@ twywpklt alice@local 2025-07-22 21:26:35 764f3651 ├─╮ (empty) (no description set) │ ○ zzywylnt alice@local 2025-07-22 21:17:31 main?? main@git f8e44920 │ │ Add Python script for greeting the world ◆ │ quolxwkk bob@local 2025-07-22 21:22:22 main?? main@origin git_head() 8d538390 ├─╯ Document hello.py in README.md ◆ kxqyrwux alice@local 2025-07-22 21:14:46 ffdf52d0 │ Add project description to readme ~
Interesting! The two parents of the new merge commit are easily visible in the commit graph. You can confirm that this new commit contains both changes from Alice and Bob:
cat README.md
cat hello.py
Jujutsu tries to be smart about how to combine changes, but not too smart. Combining changes which modify the same part of the project leads to a conflict. Conflicts are not necessarily bad, they are just a signal that you need to combine some changes manually, making sure to preserve the essence of what each change was trying to achieve individually. How to resolve conflicts is a topic reserved for the next level.
Let's wrap up this merge commit and send it to the remote:
jj commit -m "Merge code and documentation for hello-world"
jj bookmark move main --to @-
jj git push
Phew!
That was intense.
If you run jj log
now, the complicated branching and merging will be hidden by default.
Remember that you can reveal it with jj log --revisions 'all()'
.