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

Deleting commits and bookmarks

Reset your progress

To reset your progress to the start of this chapter, run the following command:

curl https://s2p2.github.io/jj-for-everyone/reset.sh | bash -s abandon
cd ~/jj-tutorial/repo

Jujutsu makes it easy to manage multiple experiments. Let's create a few:

jj commit -m "Experiment: Migrate to shiny new framework"
jj git push --change @-
jj new main
jj commit -m "Experiment: Improve scalability using microservices"
jj git push --change @-
jj new main
jj commit -m "Experiment: Apply SOLID design patterns"
jj git push --change @-
jj new main
@  vqytywws alice@local 2025-08-31 14:29:56 9bdb2d1d
│  (empty) (no description set)
│ ○  oqsqtxwo alice@local 2025-08-31 14:29:56 push-oqsqtxwowvuw 2ffeb883
├─╯  (empty) Experiment: Apply SOLID design patterns
│ ○  lqpnzsmz alice@local 2025-08-31 14:29:56 push-lqpnzsmzkxry f4cf1d7f
├─╯  (empty) Experiment: Improve scalability using microservices
│ ○  rppuwxxp alice@local 2025-08-31 14:29:56 push-rppuwxxpnkqu 8c44777f
├─╯  (empty) Experiment: Migrate to shiny new framework
◆  snnoxnvq alice@local 2025-08-31 14:29:56 main git_head() 346c0acd
│  Merge repetition and translation of greeting
~

After deciding these experiments are not good ideas, they can be deleted with jj abandon. You can abandon commits one by one, or all at once with a revset:

jj abandon 'description("Experiment")'
Abandoned 3 commits:
  oqsqtxwo 2ffeb883 push-oqsqtxwowvuw | (empty) Experiment: Apply SOLID design patterns
  lqpnzsmz f4cf1d7f push-lqpnzsmzkxry | (empty) Experiment: Improve scalability using microservices
  rppuwxxp 8c44777f push-rppuwxxpnkqu | (empty) Experiment: Migrate to shiny new framework
Deleted bookmarks: push-lqpnzsmzkxry, push-oqsqtxwowvuw, push-rppuwxxpnkqu
Hint: Deleted bookmarks can be pushed by name or all at once with `jj git push --deleted`.

jj abandon also removes local bookmarks pointing to the deleted commits. To sync these deletions with the remote, run:

jj git push --deleted

Duplicate commits when using Git directly

While Jujutsu is compatible with Git, directly modifying the repo with tools like git commit can create duplicate commits. This happens because Jujutsu doesn't realize the new Git commit is meant to replace its own working-copy commit, so it safely preserves both.

For example, committing with git after staging a file in jj:

touch some_file
jj status # record new file into working copy
git commit -am "add some file" # create commit with git, bypassing jj
jj log
@  nwstlotv alice@local 2025-08-31 14:44:23 928b48f4
│  (empty) (no description set)
○  yqyzyzzo remo@buenzli.dev 2025-08-31 14:44:22 git_head() 30e0eec4
│  add some file
│ ○  vqytywws alice@local 2025-08-31 14:44:05 70588b87
├─╯  (no description set)
◆  snnoxnvq alice@local 2025-08-31 14:29:56 main 346c0acd
│  Merge repetition and translation of greeting
~

The log shows a branched-off commit that is a duplicate of Jujutsu's previous working copy. The fix is to simply jj abandon the redundant commit.

Clean up the duplicate commit:

jj abandon main+ # abandon direct children of main

Immutability

Commands like jj abandon and jj rebase rewrite history. While powerful, rewriting history can be dangerous on shared branches like main, as it can confuse collaborators.

To prevent this, version control systems follow a rule: Never rewrite history on shared branches.

Jujutsu enforces this rule by default. Commits on shared branches are considered immutable. Attempting to modify an immutable commit will fail:

jj abandon main
Error: Commit 346c0acd36db is immutable
Hint: Could not modify commit: snnoxnvq 346c0acd main | Merge repetition and translation of greeting
Hint: Immutable commits are used to protect shared history.
Hint: For more information, see:
      - https://jj-vcs.github.io/jj/latest/config/#set-of-immutable-commits
      - `jj help -k config`, "Set of immutable commits"
Hint: This operation would rewrite 1 immutable commits.

Jujutsu marks immutable commits with a diamond (◆) in the log, while modifiable, mutable commits use a circle (○). This protection applies to all history-editing commands.