LinuxCommandLibrary

jj-squash

Combine changes into single commit

TLDR

Move all changes from current revision to its parent

$ jj squash
copy

Move all changes from given revision to its parent
$ jj squash [[-r|--revision]] [revset]
copy

Move all changes from given revision(s) to given other revision
$ jj squash [[-f|--from]] [revsets] [[-t|--into]] [revset]
copy

Interactively choose which parts to squash
$ jj squash [[-i|--interactive]]
copy

SYNOPSIS

jj squash [OPTIONS] [REVISION]

PARAMETERS

--revision <REVISION>, -r <REVISION>
    The commit to squash into its parent. If not specified, it defaults to the current working copy's commit.

--message <MESSAGE>, -m <MESSAGE>
    Use the given text as the commit message for the new parent commit. If not specified and not interactive, the original parent's message is retained.

--interactive, -i
    Open an editor to modify the commit message of the new parent commit. This allows for combining or editing messages from both the squashed and parent commits.

--tool <TOOL>
    Specify the external tool (e.g., editor) to use for interactive operations.

--ignore-unstaged
    Do not include any unstaged changes from the working copy into the resulting parent commit. By default, associated unstaged changes are also squashed.

--allow-empty
    Allow the parent commit to become empty (have no changes) after the squash operation. By default, jj squash prevents creating an empty commit unless it was already empty.

DESCRIPTION

jj squash is a fundamental command in the Jujutsu (jj) version control system, designed to simplify history rewriting. Its primary function is to combine the changes (diff) of a specified commit into its direct parent commit. This operation effectively moves the content and message of the target commit into its parent, subsequently abandoning the original (child) commit.

This command is commonly used to clean up commit history, for example, to consolidate small fix-up commits, trivial changes, or work-in-progress modifications into a more substantial, logical parent commit. It helps in maintaining a linear, readable, and clean commit graph, which is crucial for code review processes and project maintainability. Unlike jj amend, which typically modifies the current commit, jj squash specifically focuses on integrating a commit's changes into its parent, making it ideal for tidying up commit sequences from bottom-up.

CAVEATS

jj squash modifies history, which can affect collaborators if changes have been pushed and shared. While Jujutsu's mutable history model is designed for safety and ease of use, it's still good practice to coordinate with team members.

The squashed commit is abandoned, meaning it's no longer directly reachable in the visible history. However, it can be recovered using commands like jj log --abandoned followed by jj restore or jj unabandon.

This command typically operates on non-merge commits. Squashing a merge commit might have complex or unexpected behavior, or be disallowed.

DEFAULT TARGET

When no REVISION is specified, jj squash defaults to squashing the current working copy's commit into its immediate parent. This is a common use case for refining the commit you are currently working on.

UNSTAGED CHANGES

By default, any unstaged changes associated with the commit being squashed are also moved into the parent commit. The --ignore-unstaged flag provides granular control over this behavior, allowing you to keep unstaged changes separate if desired.

COMMIT MESSAGE HANDLING

If neither the --message nor --interactive flags are used, the resulting parent commit will retain its original commit message. To combine or modify messages, either provide a new message directly or use the interactive editor.

HISTORY

Jujutsu (jj) is a modern distributed version control system developed by Google, aiming to provide a more intuitive and powerful alternative to Git, especially concerning history manipulation. The jj squash command is a core component of jj's design philosophy, making history rewriting operations simple and explicit. It addresses a common need in development workflows for cleaning up commit history before sharing, similar to Git's interactive rebase with 'fixup' or 'squash' actions, but integrated as a first-class, user-friendly command within Jujutsu's powerful mutable history model.

SEE ALSO

jj amend(1), jj rebase(1), jj diff(1), jj log(1), jj restore(1)

Copied to clipboard