In developing our first two games we used Dropbox to shared and back up our files. I really like Dropbox however, it is not the best solution when it comes to syncing a lot of files, especially Unity’s library files. We also had the drawback of not being able to have Unity open on two computers at the same time. Plus we got some weird effects when Unity and Dropbox were open at the same time.
There were definitely lessons to be learnt on how to setup our work and I’m sure a lot of people will be pulling faces at the sentences above.
For our new game we have decided to use a version control system – Mercurial with TortoiseHg (windows) and SourceTree (mac). If you’re unfamiliar with it, here’s how to set it up:
- Signup for a repository (database to store all files) from Bitbucket. It is free for up to 5 users and you can use Mercurial or GIT.
- Setup your Unity project settings by enabling meta files – more information here
- Download source control program:
Setting Up Repository
Open Source Tree
Click on the button when the window below opens
Choose the Create Repository option
Select the Mercurial repository type
Add a destination path to a new folder on your mac (e.g. /Users/<my_name>/<project_name>)
Click the Create button
Double click on the new listed item to open the Source Tree project window.
Map the Bitbucket repository to the project folder on the mac:
Click on the button (on the right top corner)
Add the URL (e.g. https://<email@example.com/account_name/project_name)
Click the OK button
Click on the button to sync all the server files to your machine.
Using Version Control
When you are ready to commit your changes to the server:
- Clear out working directory files by: committing changes to local branch, reverting, deleting, or ignoring files. Right-click on selected files to perform one of the actions.
- Yellow icons show files that already exist on the server version of the project and have been modified locally.
- Green icons show files that do not exist on the server version and have been marked to be added locally.
- Red icons show files that already exist on the server version and have been marked to be deleted locally
- Blue icons show files that do not exist on the server version, they only exist locally and have not been marked to be added or removed.
- Gray icons show files that exist on the server version but are missing locally.
When ready to commit to the local repository just click the button.
- Type a description for the changes made.
- Check that the ticked files are the ones to be committed
- Click the Commit button
With all files committed to the local branch, the next step is to get the latest server changes. Click on the button.
Merge your local changes with the server files and resolve any conflicted files.
Click on the button to commit all pending changes to the server.
Using Version Control – Tortoise Hg
Using Tortoise Hg on the PC is very similar to what I described above but with a slightly different interface.
Click the (Pull) button to pull latest changes from the server repository
Click the (outgoing changes) button to view the pending changes that currently exist on your local repository
Click the (push) button to push all pending changes to the server repository
- Blue files already exist on the server version of the project and have been modified locally
- Green files don’t exist on the server version and have been marked to be added locally
- Red files already exist on the server version and have been marked to be deleted locally
- Pink files do not exist on the server version, they only exist locally and have not been marked to be added or removed
When pulling latest from the server repository and you see that the two top dots are not connected like the picture below, then:
- If you have no modified/pending files on your working or local directories and you see the red text saying “Not a head revision”: right-click on the last dot of the lower line (right-hand side) and select the Update option.
- If you do have modified/pending files on your local directory then: right-click on the last dot of the lower line (right-hand side) and select the Merge with local… option. Make sure any conflicted files are resolved.
When all is merged and updated you should only have one line as shown on the image above.
- When adding new files make sure that you check in the correspondent .meta file. For example, If I add myScript.cs file then I should also add the myScript.cs.meta file that will be displayed on the working directory list.
- To revert any pending changes just right-click on the pending files and select the Revert option.
- If there are files that you don’t wish to ever commit to the server repository you can click on the files and select the Ignore option.