jj-duplicate
Duplicate an existing commit
TLDR
Duplicate the current revision onto its existing parent
Duplicate a specific revision onto its existing parent
Duplicate a revision onto a different parent
Duplicate a revision and insert it **after** other revision(s)
Duplicate a revision and insert it **before** other revision(s)
Duplicate onto multiple parents (creates a merge commit)
Duplicate multiple revisions
SYNOPSIS
jj duplicate [OPTIONS] [REVISION]
PARAMETERS
REVISION
The commit to duplicate. If not specified, the command defaults to duplicating the working copy commit (the current commit in your workspace).
--insert-after REVISION
Make the duplicated commit a child of the specified REVISION. If the specified REVISION has multiple parents, the new commit will be inserted between REVISION and its parents, effectively re-parenting REVISION's children to the duplicated commit.
--to REVISION
Specify the parent(s) of the new duplicated commit. If this option is not provided, the new commit will inherit the same parents as the original REVISION. This option can be used multiple times to assign multiple parents, creating a merge commit.
--rebase
Automatically rebase all descendants of the original commit onto the newly duplicated commit. This is an extremely powerful option for replacing an old commit with a new version, as it ensures that the history remains coherent and subsequent changes build upon the updated commit.
--stats
Show diff statistics for the changes introduced by the duplicated commit, compared to its parents.
--color MODE
Control when to use color in the output. MODE can be always, auto (default), or never.
-h, --help
Display a short summary of available options and usage (-h) or a more detailed help message (--help).
DESCRIPTION
The jj-duplicate command creates a new commit that is an exact replica of an existing commit. This operation is fundamental in Jujutsu (jj), a modern version control system designed for flexible history manipulation. Unlike modifying an existing commit, jj-duplicate generates an entirely new commit object with a unique identifier, preserving the original's contents (tree, message, author, committer).
It's particularly useful for scenarios where you need to create an alternative version of a commit without altering the original, experiment with changes based on an existing commit, or effectively 'move' the content of a commit to a different part of your project's history. When combined with the --rebase option, it can be used to seamlessly replace an old commit with a new, duplicated one, automatically moving any subsequent commits to build on top of the new duplicate.
CAVEATS
Using jj-duplicate creates a new commit, leaving the original commit intact in the history graph. If you intend to logically 'replace' a commit, it's often used in conjunction with --rebase to move subsequent commits to build on the new duplicate. The original commit can then be abandoned if no longer needed. Always understand the implications of history manipulation, especially when working with shared repositories, as pushing duplicated commits might require careful coordination.
KEY USE CASES
Here are some common scenarios for jj-duplicate:
1. Re-parenting Commits: Change the parent(s) of a commit by duplicating it with the --to option.
2. Creating Alternatives: Generate a new commit with identical content to an existing one for experimental modifications without touching the original.
3. Replacing Obsolete Commits: Use jj duplicate --rebase to effectively 'update' an old commit in your history, ensuring all subsequent commits now build upon the new version.
4. Isolating Changes: Copy changes from one part of your repository's history to another without needing to interact with branches directly.
HISTORY
The jj-duplicate command is an integral part of Jujutsu (jj), a next-generation version control system developed to address limitations and complexities found in traditional VCS like Git. Jujutsu was initially created by Google engineers with a focus on a more intuitive and flexible command-line experience, built around a mutable history graph concept. jj-duplicate reflects this philosophy by providing a straightforward way to copy commit contents, simplifying operations that might involve more manual steps or workarounds in other systems. Its design allows for easy history rewriting and exploration, aligning with Jujutsu's goal of making complex VCS operations more accessible.
SEE ALSO
jj(1), jj-rebase(1), jj-abandon(1), jj-squash(1), jj-amend(1), git-cherry-pick(1)


