Unity scene and prefab merging using SmartMerge - lindtvedtsebastian/the-unravelling GitHub Wiki
This page explains how to merge Unity scenes and prefabs using SmartMerge.
Because Unity Scene files and Prefab files are defined in a custom and somewhat fragile way, they need to be merged with some care. It is difficult to do this by hand, and even more so to validate that the file is correct. Unity's SmartMerge does both of these things for us, and here is how to use it.
Read more about SmartMerge here: https://docs.unity3d.com/Manual/SmartMerge.html
Setup
Add the following to your global or repo level git config:
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
My path looked like: 'C:\Program Files\Unity\Hub\Editor\2020.3.18f1\Editor\Data\Tools\UnityYAMLMerge.exe'
Step by step merging
- Initiate the merge with
git merge $OTHER_BRANCH
- Git might give you an error like this:
warning: Cannot merge binary files: the-unravelling/Assets/Scenes/SampleScene.unity (HEAD vs. $OTHER_BRANCH)
Auto-merging the-unravelling/Assets/Scenes/SampleScene.unity
CONFLICT (content): Merge conflict in the-unravelling/Assets/Scenes/SampleScene.unity
Automatic merge failed; fix conflicts and then commit the result.
- In that case; use
git mergetool --tool unityyamlmerge
to resolve the conflict - UnityYAMLMerge will guide you through merging in the command line. The results will be visible in Unity Editor along the way
- Commit your changes when you are done merging
- A pair of .orig and .meta.orig files remain. These are backups of the file before merging; delete them and do not commit them.
Reference
- Managing Unity with Git: https://thoughtbot.com/blog/how-to-git-with-unity
- Git Attributes: https://www.git-scm.com/docs/gitattributes