jj-diffedit
Edit a revision's diff interactively
TLDR
Edit changes in the current revision with a diff editor
Edit changes in a given revision
Edit changes comparing a "from" revision to a "to" revision
Edit only specific paths (unmatched paths remain unchanged)
Use a specific diff editor
Preserve content instead of diff when rebasing descendants
SYNOPSIS
jj diffedit [OPTIONS] [REVISION]
jj diffedit [--revision REVISION] [--from FROM] [--to TO] [--working-copy]
PARAMETERS
-r, --revision
The revision to edit the diff for. Defaults to the current working copy commit.
--from
Compare the specified revision (or current working copy) against this FROM revision. Defaults to the parent of the chosen revision.
--to
Compare against this TO revision instead of the working copy. This is an alternative to specifying REVISION and FROM.
--working-copy
Edit the diff between the specified revision and the working copy. This is often the default or implied behavior if no --to is specified.
--tool
Specify the external diff editor to use. Overrides the default configured editor.
-h, --help
Print help information about the command.
DESCRIPTION
jj-diffedit is a powerful command within the Jujutsu (jj) version control system that enables users to interactively modify a diff and apply those changes to the working copy or a new commit. Instead of manually staging changes or using traditional patch tools, jj diffedit opens the current diff (or a specific one) in your preferred text editor. Within the editor, you are presented with the diff in a format that allows you to directly edit the proposed changes. For example, you can remove hunks, modify lines, or even add new content.
Once you save and close the editor, jj interprets your edits to the diff. It then attempts to apply these changes, either creating a new commit with the modified content or amending an existing one, depending on the context and options provided. This interactive process provides fine-grained control over the exact content and structure of your commits, making it easier to craft precise changes and maintain a clean commit history. It's particularly useful for splitting commits, selectively reverting parts of changes, or correcting mistakes before committing.
CAVEATS
Requires a configured external editor (e.g., via VISUAL/EDITOR environment variables or jj config).
Incorrectly editing the diff format (e.g., malformed hunks, changed context lines) can lead to errors, merge conflicts, or failure to apply changes.
Does not currently support editing diffs for conflicts directly; it's designed for clean changes.
Changes applied through jj diffedit may modify your working copy and potentially create new commits or amend existing ones, altering history.
HOW DIFF EDITING WORKS
When jj diffedit opens the diff in your editor, you're presented with a standard diff format (often unified diff). You can then:
- Delete entire hunks to remove those changes.
- Modify lines within hunks (e.g., change +foo to +bar, or remove a + line).
- Add new lines, ensuring they align with diff syntax (e.g., starting with + for added lines).
After saving and exiting the editor, jj attempts to apply the edited diff to the target. If the edited diff is invalid or conflicts with the base, jj will report an error and may leave you in a conflicted state or discard the changes.
EDITOR CONFIGURATION
The editor used by jj diffedit can be configured via jj config set user.diff-editor
HISTORY
jj-diffedit is a core feature of the Jujutsu (jj) SCM, which is a relatively modern version control system designed to improve upon Git's user experience, especially around rewriting history and managing branches. The diffedit command was developed as part of jj's philosophy to provide powerful, interactive tools for manipulating changes and commits directly. It emerged from the need for a more intuitive and integrated way to craft precise commits, addressing some of the pain points associated with Git's staging area and patch application workflows. Its design reflects jj's focus on making history rewriting and change management explicit and user-friendly from its inception.


