Main Content

Register External Text Merge Tool

R2026b
Since R2026b

By default, to resolve merge conflicts in text-based files, MATLAB® uses a built-in two-way text merge tool. Starting in R2026b, you can also register an external three-way merge tool. Once registered, the external tool launches automatically when you click View Conflicts for conflicted text-based files, including .m, .txt, and TOML files.

Use an external merge tool when you prefer a three-way merge view for text files or want to use the same conflict resolution workflows that you already use outside of MATLAB.

Configure External Merge Tool

To register an external merge tool, use the ExternalMergeTool setting to specify the command that MATLAB runs when you resolve a conflict.

s = settings;
s.comparisons.text.ExternalMergeTool.PersonalValue = '<absolute/path/to/tool> "%THEIRS" "%BASE" "%MINE" "%TARGET"';

Replace <absolute/path/to/tool> with the absolute path to your merge tool executable. The argument order and flags depend on the tool. For example:

  • meld (Linux®):

    s.comparisons.text.ExternalMergeTool.PersonalValue = '/usr/bin/meld "%THEIRS" "%BASE" "%MINE" --output "%TARGET"';
  • P4Merge (Windows®):

    s.comparisons.text.ExternalMergeTool.PersonalValue = 'C:/Program Files/Perforce/p4merge.exe "%THEIRS" "%BASE" "%MINE" "%TARGET"';

When MATLAB launches the external tool, it replaces the %THEIRS, %BASE, and %MINE values with the actual file paths involved in the merge.

MacroDescription
%BASEThe common ancestor version of the file.
%THEIRS or %REMOTEThe incoming version of the file from the branch you want to merge.
%MINE or %LOCALYour local version of the file from the current branch.
%TARGET or %MERGEDThe output file where MATLAB writes the merged result.

Note

To handle file paths that contain spaces, enclose the macros in double quotes (for example, "%BASE").

To revert to the built-in MATLAB merge tool, clear the setting:

s.comparisons.text.ExternalMergeTool.clearPersonalValue; 

Choose Whether to Trust Exit Code

The ExternalMergeToolTrustExitCode setting controls whether MATLAB uses the exit code of the external tool to determine the success of the merge.

To configure the exit code trust preference of the external tool, set s.comparisons.text.ExternalMergeToolTrustExitCode.PersonalValue to one of these options:

  • true — If the tool exits with code 0, MATLAB automatically marks the conflict as resolved.

  • false — MATLAB does not use the exit code. After the tool closes, you must manually mark the conflict as resolved. This is the default value.

For example, to trust the exit code of the external tool, in MATLAB, enter:

s.comparisons.text.ExternalMergeToolTrustExitCode.PersonalValue = true;

See Also

Topics