LinuxCommandLibrary

jj-prev

Switch to the previous commit

TLDR

Move the working-copy commit to the previous parent revision

$ jj prev
copy

Move the working-copy commit a number of revisions backward
$ jj prev [offset]
copy

Edit the parent revision directly, instead of creating a new working-copy commit
$ jj prev [[-e|--edit]]
copy

Create a new working-copy commit instead of editing the parent revision directly
$ jj prev [[-n|--no-edit]]
copy

Jump to the previous conflicted parent
$ jj prev --conflict
copy

SYNOPSIS

jj prev [OPTIONS]

PARAMETERS

-r , --revision
    The revision to operate on. If not specified, the working copy commit is used. The command will then try to move the working copy to the parent of this revision.

--at
    Where to put the working copy. This option only makes sense if --revision is also specified. By default, the working copy is moved to the parent of the --revision target.

--ignore-working-copy
    If specified, the command will not change the working copy commit. Instead, it will simply print the ID of the calculated 'previous' commit. This is useful for scripting or inspecting without modifying your workspace.

-n , --count
    How many parents to go back. For instance, -n 2 would move to the grandparent commit. Defaults to 1.

-m , --parent
    Which parent to select when a commit has multiple parents (e.g., a merge commit). Parent 0 is usually the 'main' parent, parent 1 is the 'secondary' parent, and so on. Defaults to 0.

DESCRIPTION

The jj-prev command in Jujutsu (jj) is a fundamental navigation utility that allows users to move the current working copy commit, or a specified revision, to its parent commit. This facilitates stepping backwards through the repository's history, enabling quick review of previous states, debugging by isolating changes, or preparing to create new branches from an earlier point.

By default, it operates on the commit currently associated with your working copy, effectively updating your local workspace to reflect the chosen parent commit. Jujutsu handles uncommitted changes by rebasing them onto the new parent, ensuring a smooth transition without losing work. For commits with multiple parents (e.g., merge commits), jj-prev provides options to specify which parent to move to.

CAVEATS

When dealing with merge commits, the concept of a 'single previous' commit becomes ambiguous. By default, jj-prev selects the first parent (parent 0). To navigate to other parents of a merge commit, you must explicitly use the --parent option. Users should be aware that moving the working copy commit changes the current state of their repository, though Jujutsu's mutable history model and automatic rebase of uncommitted changes typically makes this a non-destructive operation.

DEFAULT BEHAVIOR

By default, jj-prev operates on the current working copy commit and moves it to its immediate first parent. Any uncommitted changes in the working copy are automatically rebased onto the new parent commit, preserving your work.

NAVIGATION PHILOSOPHY

Jujutsu's navigation commands like jj-prev, jj-next, and jj-goto are designed to provide a more fluid way to explore and manipulate history compared to traditional VCS tools. They encourage interactive rebasing and reordering of changes, aligning with Jujutsu's mutable history paradigm.

HISTORY

Jujutsu (jj) is a modern, experimental version control system developed by Martin Karlsson, which began gaining traction around 2022-2023. It aims to offer a fresh perspective on VCS, combining features from Git, Mercurial, and Pijul, with a strong focus on a mutable history model and an improved user experience. The jj-prev command is a core component of its intuitive navigation capabilities, designed to simplify moving through the commit graph compared to traditional VCS workflows.

SEE ALSO

jj-next(1), jj-goto(1), jj-back(1), jj-checkout(1), jj-log(1), git-checkout(1), git-reset(1)

Copied to clipboard