Resolve merge conflict for Unity Game Engine

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
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:

# Autogenerated VS/MD solution and project files
# Unity3D generated meta files
# Unity3D Generated File On Crash Reports
# Builds

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 UnityYAMLMerge for merging scene and prefab files. Enable this by creating a .gitconfig file with following:

tool = unityyamlmerge
[mergetool “unityyamlmerge”]
trustExitCode = false
cmd = /Applications/Unity/ 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!

By Victor Leung

Experience in software development, consulting services and technical product management. Understanding of business and technology with an MBA in Finance and a Master degree in Computer Science. AWS Certified Solution Architect with experience in building products from scratch and serving as a charismatic leader.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: