unity3d Scenes and Prefabs merging


Example

A common problem when working with Unity is when 2 or more developers are modifying a Unity scene or prefab (*.unity files). Git does not know how to merge them correctly out of the box. Thankfully the Unity team deployed a tool called SmartMerge which makes simple merge automatic. The first thing to do is to add the following lines to your .git or .gitconfig file: (Windows: %USERPROFILE%\.gitconfig, Linux/Mac OS X: ~/.gitconfig)

[merge]
tool = unityyamlmerge

[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

On Windows the path to UnityYAMLMerge is :

C:\Program Files\Unity\Editor\Data\Tools\UnityYAMLMerge.exe

or

C:\Program Files (x86)\Unity\Editor\Data\Tools\UnityYAMLMerge.exe

and on MacOSX :

/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge

Once this is done, the mergetool will be available when conflicts arise during merge/rebase. Don't forget to run git mergetool manually to trigger UnityYAMLMerge.