Correctly using external Version Control Systems with Unity

This post describes the how I set up new Unity projects for use with an external VCS, which is based on the process described in the Unity documentation, but corrects a few omissions that unnecessarily include unneeded files in source control. And while I’ll be using Subversion in this example, the process should be applicable to other VCSs by changing the Subversion commands used here to their appropriate counterparts.

Step 1: Turn on meta files

Starting with a new project or an existing project that is not managed by source control, select the Edit → Project Settings → Editor menu option. From the inspector that will be shown, change the Version Control Mode from Disabled to Meta Files as shown below:

 

Step 2: Force asset serialization to text mode

From the same Inspector panel, change the Asset Serialization Mode from Mixed to Force Text as shown below:

 

This feature is only available in Unity Pro. It’s perfectly possible to work with Subversion without it, but having it turned on makes it possible to merge changes to scenes and prefabs from multiple users.

Step 3: Delete files and folders that will not be added to source control

Quit Unity and save all changes. Then in your project’s folder, delete the Library folder and the Temp folder if one exists. Also delete all files with the extensions csprojsln, pidb, and userprefs. These file types are used by MonoDevelop, and Unity will recreate them if they are not present.

Step 4: Make the initial commit to source control

Step 5: Check out the project from source control

Either delete all files in your project’s folder or, to be extra safe, create a new folder and run the checkout command inside either one:

Now open the checked out project in Unity and confirm that everything is working a-okay.

Step 6: Add ignore filters

It’s best to tell Subversion to ignore all the files and folders that were deleted in step 3 above. That we they won’t show in the output of the status command and they they won’t be added to source control by accident.

I keep a file named unity-svn-ignore.txt somewhere on my Dropbox folder that has all the ignore patters needed for Unity projects. Download it and apply it using the svn propset command:

You can also set the ignore filter using your favorite text editor by running the propedit command:

Paste the following content in the text editor once it’s opened:

Save the file and quit your text editor.

Step 7: Commit the changes to source control

The ignore folder is stored as a property on the project folder. So it needs to committed to source control:

And you’re done!

Subversion is different from most VCSs that in the sense that it needs to have a repository before being able to ignore files in it. All other version control systems I know of like Mercurial and Git store this information in special files. For those systems, step 4 is not needed, and the initial commit can be done at the end of the process.z

Leave a Reply