Configure Unity's Smart Merge tool with Git for collaborative development
...without hardcoding the Editor path anywhere
Windows only
touch .gitconfigSince this .gitconfig you've just created
is not automatically seen and used by Git,
we need to tell Git to include it (for the current repository only):
git config --local include.path ../.gitconfigImportant
(Unfortunately) all collaborators in your repository have to run this command as well. I recommend adding the note to the README.md.
File run_unity_merge_tool.sh:
BASE=$1
REMOTE=$2
LOCAL=$3
MERGED=$4
# Find UnityYAMLMerge.exe tool automatically
find /c/Program\ Files/Unity/ -name 'UnityYAMLMerge.exe' -exec '{}' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED" ';'Or the .bat equivalent (run_unity_merge_tool.bat):
@echo off
rem Find UnityYAMLMerge.exe tool automatically
for /R "C:\Program Files\Unity" %%f in (UnityYAMLMerge.exe) do if exist "%%f" set "unityyamlmerge=%%f"
set BASE=%1
set REMOTE=%2
set LOCAL=%3
set MERGED=%4
"%unityyamlmerge%" merge -p "%BASE%" "%REMOTE%" "%LOCAL%" "%MERGED%"[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = ./run_unity_merge_tool.sh "$BASE" "$REMOTE" "$LOCAL" "$MERGED"If you decided to use the .bat version, simply change to ./run_unity_merge_tool.bat
When you encounter merge conflicts in YAML assets (scenes, prefabs, materials etc.), run:
git mergetool
And it should try to automatically resolve the conflicts