Diff Command
The--diff flag opens a diff view comparing two files or directories. This is
useful for reviewing changes, comparing versions, or exploring differences
between configurations.
Basic File Diff
Compare two files:- Left pane:
old-file.txt(OLD_PATH) - Right pane:
new-file.txt(NEW_PATH)
Multiple Diffs
Compare multiple pairs of files in a single session:--diff multiple times. Each pair opens as a separate diff
view.
Directory Diff
Compare two directories:- Recursively walks both directories
- Collects all files
- Matches files by relative path
- Shows all changed files in a single multi-diff view
Directory Diff Behavior
Files present in both directories:- Displayed as a standard diff
- Left pane: original file
- Right pane: empty stub file
- Left pane: empty stub file
- Right pane: new file
Argument Format
The--diff flag accepts exactly two arguments:
- OLD_PATH: The original or “before” file/directory
- NEW_PATH: The modified or “after” file/directory
- An absolute path:
/home/user/file.txt - A relative path:
src/main.rs - A non-existent path (Zed will handle it gracefully)
Path Positioning
Diff paths support line and column positioning:Combining with Other Options
Wait for Closure
Wait until the diff view is closed:New Window
Open the diff in a new window:Add to Current Workspace
Add the diff to the currently focused workspace:Workspace Context for Diffs
When only diff paths are provided (no regular file/directory paths), Zed automatically adds the current working directory to the workspace. This ensures:- The workspace opens with proper context
- File tree navigation is available
- Project-specific settings apply
~/projects/myproject workspace.
Implementation Details
Temporary Files
When comparing directories with files present in only one directory, Zed creates empty stub files in a temporary directory. These files:- Are created in the system temp directory
- Use the same relative path structure as the original
- Are kept (not auto-deleted) to prevent premature cleanup
- Are cleaned up by the OS on system reboot
Path Canonicalization
Diff paths are canonicalized using the same logic as regular paths:- Existing paths are fully canonicalized
- Non-existing paths have their existing portion canonicalized
- The result is always an absolute path
Multi-Diff Mode
When any diff path is a directory, Zed enters “multi-diff mode” which:- Processes all file pairs at once
- Uses a unified diff view for all changes
- Groups related changes together
Examples
Compare Files Before Committing
Review Changes in Two Project Versions
Compare Multiple Configuration Files
Diff and Wait for Review
Compare with Git Versions
See Also
- CLI Overview - Introduction and basic usage
- Open Command - Opening files and projects
- CLI Options - Complete reference for all flags
