LinuxCommandLibrary

jj-commit

Create new commit

TLDR

Open editor to write the commit message and then create a new empty commit on top

$ jj commit
copy

Commit with the given message
$ jj commit [[-m|--message]] "[message]"
copy

Interactively choose which changes to include
$ jj commit [[-i|--interactive]]
copy

SYNOPSIS

jj commit [OPTIONS]

PARAMETERS

-m, --message <MESSAGE>
    Sets the initial commit message. This message will be used as the commit's summary line.

-d, --description <DESCRIPTION>
    Sets a longer description for the commit, which appears below the summary line. This is analogous to the body of a Git commit message.

-i, --interactive
    Launches an interactive session (using a diff editor) to allow you to select which changes (hunks) should be included in the commit. This provides granular control over what gets committed.

-e, --empty
    Forces the creation of a new, empty commit, even if there are uncommitted changes in the working directory. If there are changes, they will not be included in this new empty commit but will remain in the working copy.

-r, --revision <REVISION>
    Specifies the revision to commit on top of. By default, jj-commit operates on the current working copy commit. This option allows you to create or amend a commit other than the working copy.

--tool <TOOL>
    Specifies the external tool to use for interactive operations (e.g., when --interactive is used). Examples include jj-diff-editor or other configured diff tools.

DESCRIPTION

jj-commit is a fundamental command within the Jujutsu (jj) distributed version control system. Its primary function is to record changes from your working directory into a commit.

Unlike traditional Git workflows, jj-commit operates directly on the 'working copy commit'—the specific commit currently checked out in your workspace. If there are uncommitted changes (modifications to tracked files or new untracked files), jj-commit will amend this working copy commit by incorporating those changes. If the working copy is clean (no uncommitted changes), jj-commit will create a new, empty commit on top of it.

This command simplifies the commit process by implicitly including all changes by default (similar to git commit -a), reducing the need for an explicit staging area. You can provide a commit message and an optional extended description.

CAVEATS

Behavioral Difference from Git: Unlike git commit, jj-commit does not create a new commit on top of the previous one if there are uncommitted changes. Instead, it amends the current working copy commit. To create a truly separate new commit, you would typically use jj new first.

Automatic Inclusion: By default, jj-commit includes all modified and untracked files in the commit, similar to git commit -a. An explicit 'staging area' as seen in Git is not present in Jujutsu's default workflow.

WORKING COPY COMMIT CONCEPT

In Jujutsu, your working directory is always associated with a specific 'working copy commit'. All your edits and uncommitted changes are conceptually applied on top of this commit. jj-commit directly targets and updates this specific commit, making the workflow feel more fluid and less reliant on managing an intermediate staging area.

IMPLICIT STAGING

One of Jujutsu's distinct features is the absence of an explicit staging area (like Git's index). When you run jj commit (without --interactive), all changes in your working directory, including modifications to tracked files and new untracked files, are automatically considered for the commit. This design choice aims to simplify the most common commit workflows.

HISTORY

Jujutsu (jj) is a relatively modern distributed version control system, open-sourced by Google. It was designed to offer a fresh perspective on version control, aiming to improve upon common pain points found in traditional systems like Git, especially concerning mutable history and large monorepo management. jj-commit is a core command that embodies Jujutsu's design philosophy, simplifying the commit workflow by integrating the 'staging' step and defaulting to amending the working copy commit, thereby streamlining common user interactions.

SEE ALSO

jj new, jj amend, jj diff, jj status, jj log, git commit(1)

Copied to clipboard