LinuxCommandLibrary

jj-rebase

Move commits to new parent

TLDR

Move given revisions to a different parent(s)

$ jj rebase [[-r|--revisions]] [revset] [[-d|--destination]] [revset]
copy

Move given revisions and all their descendants
$ jj rebase [[-s|--source]] [revset] [[-d|--destination]] [revset]
copy

Move all revisions in the branch containing given revisions
$ jj rebase [[-b|--branch]] [revset] [[-d|--destination]] [revset]
copy

Move revisions to before and/or after other revisions
$ jj rebase [[-r|--revisions]] [revset] [[-B|--insert-before]] [revset] [[-A|--insert-after]] [revset]
copy

SYNOPSIS

jj rebase [OPTIONS] { --from <REVISION> --to <REVISION> | --revision <REVISIONS>... --onto <REVISION> | --branch <NAMES>... --onto <REVISION> }

PARAMETERS

--from <REVISION>
    The old parent(s) of the changesets to be rebased. Specifies the starting point for the rebase range.

--to <REVISION>
    The new parent for the changesets that were previously descendants of --from. Specifies the destination parent.

--onto <REVISION>
    The new parent for the changesets specified by --revision or --branch. An alternative way to specify the destination.

-r, --revision <REVISIONS>...
    The specific changeset(s) to rebase. Multiple revisions can be specified, which will be rebased onto the --onto target.

-b, --branch <NAMES>...
    Rebase all changesets on the specified branch(es) onto the --onto target.

-s, --source <REVISION>
    Alias for --from, specifying the source parent.

-d, --destination <REVISION>
    Alias for --to, specifying the destination parent.

-i, --interactive
    Start an interactive rebase session, allowing you to reorder, edit, squash, or split changesets.

--insert-after <REVISION>
    When used with interactive rebase, inserts new changesets after the specified revision in the rebase plan.

-m, --message <MESSAGE>
    Set the commit message for the new, rebased changeset.

DESCRIPTION

jj rebase is a fundamental command in the Jujutsu (jj) version control system, used to move or rewrite changesets (commits) by changing their parent. Unlike Git's rebase, which often destructively rewrites history, jj rebase operates on Jujutsu's immutable history model. This means that when a rebase occurs, new changesets are created for the rebased content, while the original changesets are preserved and become hidden. This allows for safer experimentation and easier undo operations. The command is essential for cleaning up commit history, integrating changes from a main branch into a feature branch, or reordering/squashing changesets before merging. It re-applies the differences of the specified changesets relative to their new parent, offering powerful capabilities for history manipulation in a controlled and recoverable manner.

CAVEATS

Unlike Git's rebase, jj rebase creates new changesets for the rebased content, preserving the original (now hidden) changesets. This makes rebase operations in Jujutsu inherently non-destructive and easily revertible using commands like jj undo or jj restore. Conflict resolution during rebase requires using jj diff --tool and manually resolving changes, followed by jj new or jj finish.

INTERACTIVE REBASE WORKFLOW

The --interactive (-i) flag initiates an interactive rebase. This opens an editor (configured by jj config ui.editor) with a list of changesets to be rebased. Users can then reorder, pick, fold (squash), or edit individual changesets. This powerful feature allows for meticulous refinement of commit history before sharing, making complex history rewrites straightforward.

COMMON USAGE PATTERNS

A common use case is to update a feature branch with the latest changes from a main branch: jj rebase -b my-feature -d main. Another is to clean up a series of commits by interactively reordering or squashing them. For example, to interactively rebase the current commit and its ancestors: jj rebase -i -r @- (where @- refers to the parent of the working copy's commit).

HISTORY

Jujutsu (jj) is a relatively new version control system, developed by Google, aiming to provide a more intuitive and powerful alternative to Git, especially for large monorepos and complex workflows. Its design is influenced by concepts from Mercurial and Pijul, emphasizing atomic changesets and an immutable history model. jj-rebase is a core command that embodies these principles, offering a flexible and safe way to manipulate commit history, distinguishing itself significantly from Git's rebase due to its non-destructive nature and efficient handling of changesets.

SEE ALSO

jj-diffedit(1), jj-squash(1), jj-move(1), jj-edit(1), jj-undo(1)

Copied to clipboard