Resolve merge conflict for Unity Game Engine

May 21, 2016

I’m working in a group of 4 teammates for a unity 3D game project on the weekends. It’s pretty fun, but we have encounter problems with version control. Using Git and Github, there are many merge conflicts that it’s not easy to resolve, not simply delete a section or forced push:

    <<<<<<< HEAD:main.scene
    Painful
    =======
    Delete me
    >>>>>>>

There are lots of unnecessary local meta files that are pushed to our repository. Here is the solution I got, which is not perfect, but it works:

Firstly, open the unity editor, go to

    Edit -> Project Settings ->Editor ->
    Select “**Visible Meta files**” in version control mode

Secondly, add the .gitinore file like this:

    /[Ll]ibrary/
    /[Tt]emp/
    /[Oo]bj/
    /[Bb]uild/
    /[Bb]uilds/
    /Assets/AssetStoreTools*

    # Autogenerated VS/MD solution and project files
    ExportedObj/
    *.csproj
    *.unityproj
    *.sln
    *.suo
    *.tmp
    *.user
    *.userprefs
    *.pidb
    *.booproj
    *.svd

    # Unity3D generated meta files
    *.pidb.meta

    # Unity3D Generated File On Crash Reports
    sysinfo.txt

    # Builds
    *.apk
    *.unitypackage

    .DS_Store

Then commit the actual changes and run the following command:

    git rm -r — cached .
    git add .
    git commit -m “fixed untracked files”

Thirdly, Unity has a tool called UnityYAMLMergefor merging scene and prefab files. Enable this by creating a .gitconfig file with following:

    [merge]
    tool = unityyamlmerge

    [mergetool “unityyamlmerge”]
    trustExitCode = false
    cmd = /Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge merge -p “$BASE” “$REMOTE” “$LOCAL” “$MERGED”

Next time a teammate clone the project, he would probably just see an empty scene. But don’t panic, open the saved main.scene (hopefully you saved the scene and committed it), then the rest should work as expected. I wish Unity could have source control build in by default like other IDE environment. Happy coding!


Profile picture

Experience in software development, application architecture, and deploying cloud solutions for enterprise customers. Strong hands-on skills with a Master's degree in Computer Science and business acumen with a master of business administration (MBA) in Finance. Certified in Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, Kubernetes (CKA, CKAD, CKS, KCNA) and Scrum (PSM, PSPO) with experience in building banking products from scratch. Connect on Linkedin

© 2022, @victorleungtw