- 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
- Add a merge tool, once per computer. This one merges JSON files:
- Merge with your tools:
- 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.
How it works
- You start a merge, update, or revert with the
merge-toolconflict resolution. - 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.
- 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.
- If the tools resolve every conflict, Diversion completes the merge and creates the commit.
- 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:
--cmdmust 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
--cmdvalue in single quotes. Otherwise your shell replaces$ANCESTORand the other placeholders before Diversion sees them.
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 asgit 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
$RESULTand 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 toForce 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.
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 with0 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:
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
~/.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
Related
dv merge-tool— CLI reference for managing merge tools- Conflicts — types of conflicts and how to resolve them
- Branching and merging
- Unity best practices

