In the Unity editor:
- Edit -> Project Settings -> Editor
- In the inspector panel, set:
- Version Control -> Mode: Visible Meta Files
- Asset Serialization -> Mode: Force Text
“Visible Meta Files” causes Unity to place .meta
files next to each of your assets. It’s important to check these files into version control because they contain the settings associated with those assets that you set in the Unity editor.
“Asset Serialization: Force Text” causes Unity to write its .meta
and other files in a more-or-less human-readable text format, which makes it a lot easier to understand what has changed when you look at version control logs. Also it’s feasible to merge these text files by hand, whereas it’s not really possible to do that with Unity’s default binary file format.
Create a .gitignore
file in the root of your project with the following contents:
/Temp
/Library
/Obj
/UnityGenerated
/Build
/Builds
/*.sln
/Assembly-CSharp.csproj
*.suo
*.user
*.userprefs
Most of the stuff in the above ignore file is stuff generated by Unity when you open or build your project, so you don’t need to check that stuff in. Usually in a .NET project you would check in the *.sln
and *.csproj
files, but in a Unity project Unity will generate those so it’s best not to check them in.
*.suo
files are generated by Visual Studio when you open your project, you don’t need to check that in. (MonoDevelop probably also generates these files but I’m not sure).
*.user
and *.userprefs
contains Visual Studio settings that are specific to an individual PC, you shouldn’t check these in. (MonoDevelop probably also generates these files but I’m not sure).
If you use Blender, add the following to the .gitignore
also:
*.blend1
*.blend1.meta
Create a .gitattributes
file in the root of your project with the following contents:
*.sln text eol=crlf
*.csproj text eol=crlf
*.anim text eol=lf
*.asmdef text eol=lf
*.asset text eol=lf
*.controller text eol=lf
*.mat text eol=lf
*.meta text eol=lf
*.overrideController text eol=lf
*.prefab text eol=lf
*.preset text eol=lf
*.spriteatlas text eol=lf
*.unity text eol=lf
*.mixer text eol=lf
*.renderTexture text eol=lf
*.json text eol=lf
*.xml text eol=lf
This ensures that .NET project files are stored with CRLF line endings, which is required by the .NET spec. It also ensures that Unity *.asset
files are stored with LF line endings. Unity always uses LF line endings for these files regardless of platform.
The .gitattributes
file is not mandatory, and nothing will break if you don’t include it. However, if you don’t, then depending on your platform these files may show as having changes whenever Unity rewrites the file, even if the contents of the file are the same, which can be very annoying.
I've just checked Unity 2018.3 fresh project (without git control) and some
*.asset
files are with CRLF others with LF. Seems Unity is inconsistent itself.On the other hand, seems to me that
*.meta
files are with LF.