merge command performs a three-way merge between the destination state (your current file), the source state (in your chezmoi directory), and the target state (what chezmoi wants to apply).
Usage
Description
Themerge command invokes your configured merge tool to help resolve conflicts between three versions of a file:
- Destination - The current state of the file in your home directory
- Source - The file in chezmoi’s source directory
- Target - The computed target state (templates evaluated, files decrypted, etc.)
merge.command configuration variable and defaults to vimdiff. If multiple targets are specified, the merge tool is invoked separately and sequentially for each target.
If the target state cannot be computed (e.g., a template with errors or an encrypted file that cannot be decrypted), a two-way merge is performed instead.
Merge Command Arguments
The order of arguments tomerge.command is set by merge.args. Each argument is interpreted as a template with these variables:
.Destination- Path to the file in the destination state.Source- Path to the file in the source state.Target- Path to the file in the target state
["{{ .Destination }}", "{{ .Source }}", "{{ .Target }}"]
If merge.args doesn’t contain template arguments, the three paths will be appended automatically.
Configuration
Configure your merge tool in your config file:Examples
Merge a single file
.bashrc.
Merge multiple files
Workflow
- Detect conflict - Use
chezmoi statusorchezmoi diffto identify files with conflicts - Merge - Run
chezmoi merge <file>to resolve conflicts - Review - Use your merge tool to choose which changes to keep
- Save - The source file is automatically updated when you save and exit
- Apply - Run
chezmoi applyto apply the merged changes
Example Workflow
Encrypted Files
For encrypted files, chezmoi automatically:- Decrypts the source file to a temporary directory
- Invokes the merge tool with the decrypted plaintext
- Re-encrypts the file after you save and exit
Template Files
For template files, the merge shows:- Destination: Your current file
- Source: The template source with
{{ }}syntax - Target: The evaluated template