Skip to main content
When a merge has conflicts, Diversion can run a merge tool that you choose on each conflicting file. The tool merges the two versions of the file, and Diversion saves the result to the merge. Use this for files that need a special merge tool, for example:
  • Unity scenes and prefabs, with UnityYAMLMerge (Unity Smart Merge)
  • JSON, YAML, or source code, with a syntax-aware tool such as mergiraf
  • Any file that you want to merge by hand in a visual tool, such as KDiff3 or Meld

Quick start

  1. Add a merge tool, once per computer. This one merges JSON files:
  2. Merge with your tools:
  3. Diversion merges what it can on the server. For each conflict that is left, it runs the tool that matches the file. If a conflict is still open at the end, finish it in the Diversion app.
For Unity and other tools, see Examples.

How it works

  1. You start a merge, update, or revert with the merge-tool conflict resolution.
  2. Diversion first merges what it can on the server. If the two sides changed different parts of a text file, Diversion merges it for you, and no tool runs.
  3. For each conflict that is left, Diversion finds the first tool whose pattern matches the file path. It downloads the versions of the file to temporary files and runs the tool.
  4. If the tools resolve every conflict, Diversion completes the merge and creates the commit.
  5. If some conflicts are not resolved, the merge stays open. You resolve the rest in the Diversion app. The conflicts that the tools resolved stay resolved.
Merge tools run on your computer. Your tool settings are saved for your user on this computer, not in the repository, so each team member sets up their own tools.

Set up a merge tool

1

Install the tool

Install the merge tool and find the full path to its program. If the program is on your PATH, the program name is enough.
2

Add the tool to Diversion

Tell Diversion which files the tool handles and how to run it:
See Examples for ready-to-use commands.
3

Check your setup

List your tools, in the order Diversion matches them:

Command placeholders

In --cmd, use these placeholders for the file paths. Diversion replaces them with temporary files before it runs the tool. Rules for the command:
  • --cmd must include $RESULT.
  • The command runs directly, not through a shell. Pipes (|), redirects (>), and environment variables do not work. If you need them, put the steps in a script, and set the script as the command.
  • Put double quotes around a program path that has spaces.
  • On Mac and Linux, put the whole --cmd value in single quotes. Otherwise your shell replaces $ANCESTOR and the other placeholders before Diversion sees them.
The temporary files keep the original file extension, for example local.prefab. This matters for tools that choose how to merge from the extension, such as UnityYAMLMerge and mergiraf.

File patterns

--pattern is a regular expression. Diversion matches it against the file path in the repository. If more than one tool matches a file, the first tool in the list wins. dv merge-tool add puts a new tool at the end of the list. Use dv merge-tool to see the order. A file that matches no tool is left for you to resolve in the Diversion app.

Exit codes and visual tools

By default, the exit code of the tool decides the result, the same way as git mergetool: Some visual tools exit with 0 even when you close them without saving. For these tools, add --no-trust-exit-code. Diversion then ignores the exit code and checks $RESULT:
  • If the tool wrote $RESULT and the file has no conflict markers (<<<<<<<), the conflict is resolved.
  • Otherwise, Diversion asks: Was the merge successful? [y/n].
  • If there is no terminal to ask in, for example in a CI job, the conflict stays unresolved.

Examples

Unity Smart Merge (UnityYAMLMerge)

UnityYAMLMerge comes with the Unity Editor. It merges Unity scenes, prefabs, and other YAML assets. It works only on assets saved as text, so set Asset Serialization Mode to Force Text first (see Unity best practices). Change 6000.0.23f1 to your Unity version:
UnityYAMLMerge takes the files in the order base, remote, local, merged. This is different from most other tools.
On Windows, run the example in Command Prompt. PowerShell passes quotes inside arguments differently in different versions, so the quoted program path can break.

mergiraf (JSON, YAML, and code)

mergiraf understands the syntax of many file types. It can merge two changes on the same line, such as two new keys in one JSON object.

KDiff3

KDiff3 merges what it can on its own. It opens a window only when a conflict is left for you.

Meld

Meld exits with 0 even when you close it without saving, so add --no-trust-exit-code:

Resolve conflicts with your merge tools

From the CLI

Add --conflict_resolution merge-tool to dv merge, dv update, or dv revert:
If you have no tools set up, the command stops before it starts the merge. The tools run one conflict at a time. The CLI then prints the result for each file:
Diversion completes the merge only when every conflict is resolved. If any conflict is skipped or failed, the merge stays open and the command exits with a non-zero exit code, so scripts can detect it.

Manage your merge tools

When you add a tool with a name that already exists, Diversion replaces it and keeps its place in the list. Diversion saves your tools in ~/.diversion/merge_tools.json (on Windows, %USERPROFILE%\.diversion\merge_tools.json). Use dv merge-tool to change them instead of editing the file. See dv merge-tool for all options.

Troubleshooting