Unity supports version control integration with Perforce and Plastic SCM. Refer to those pages for specific information regarding your choice of version control.
Using a version control system makes it easier for a user (or multiple users) to manage their code. It is a repository of files with monitored access. In the case of Unity, this is all the files associated with a Unity project. With version control, it is possible to follow every change to the source, along with information on who made the change, why they made it, and what they changed. This makes it easy to revert back to an earlier version of the code, or to compare differences in versions. It also becomes easier to find out when a bug first occurred, and with what changes might have caused it.
Get your version control software setup according to its instructions, then follow these steps:
Set up or sync a workspace on your computer using your chosen client (refer to the Plastic SCM Integration guide or the Perforce Integration guide for help with this step).
Copy an existing project into the workspace, or start Unity and create a new project in the workspace.
Open the project and go to Edit > Project Settings, then select the Editor category.
Under Version Control, choose your Mode according to the version control system that you chose.
Заполните настройки системы контроля версий, такие как логин / пароль/ сервер / рабочая папка.
Keep Automatic add checked if you want your files to be automatically added to version control when they’re added to the project (or the folder on disk). Otherwise, you need to add new files manually.
You have the option to work offline. This mode is only recommended if you know how to manually integrate changes back into your version control software (Working offline with Perforce).
You can edit the Asset Serialization, Default Behaviour Mode and Sprite Packer options to suit your team’s preferences and choice of version control.
Click Connect and verify that “Connected” is displayed above the Connect button after a short while.
Use your standard client (e.g. p4v) to make sure that all files in the Assets and ProjectSettings folders (including files ending with .meta) are added.
Обратите внимание, что в любой момент вы можете перейти в меню Prefences и выбрать пункт External Tools и настроить Revision Control Diff/Merge Tool.
At this point you should be able to do most of the important version control operations directly by right-clicking on the assets in the project view, instead of going through the version control client. The version control operations vary depending on which version control you choose, this table shows what actions are directly available for each version control:
Процедура проверки версии | Описание | Perforce | Plastic SCM |
Проверка | Все изменения записываются в файл | Да | Да |
Diff against head | Compares differences between file locally and in the head | Да | Да |
Получить последнюю | Pull the latest changes and update file | Да | No* |
Блокировка | Prevents other users from making changes to file | Да | No** |
Mark Add | Add locally but not into version control | Да | Да |
Resolve Conflicts | To resolve conflicts on a file that has been changed by multiple users | Да | No*** |
Revert | Discards changes made to open changed files | Да | Да |
Revert Unchanged | Discards changes made to open unchanged files | Да | Да |
Подтвердить | Submits current state of file to version control | Да | Да |
Разблокировать | Снимает запрет и позволяет вносить изменения любому желающему | Да | No** |
* To get the latest changes and update the file using Plastic SCM, you need to use the version control window.
** Locking and Unlocking using Plastic SCM require you to edit a specific Plastic SCM lock file externally, see the Plastic SCM Integration page for more information.
*** Conflicts are shown within the version control menu but resolved in the Plastic SCM GUI.
You can overview the files in your changelist from the Version Control Window (Window > Asset Management > Version Control). It is shown here docked next to Inspector in the editor:
The ‘Outgoing’ tab lists all of the local changes that are pending a commit into version control whereas the ‘Incoming’ tab lists all of the changes that need to be pulled from version control.
By right clicking assets or changelists in this window you perform operations on them. To move assets between changelists just drag the assets from one changelist to the header of the target changelist.
The following icons are displayed in Unity editor to visualize version control status for files/assets:
Значки | Предположение (Meaning) | Дополнительная информация (Additional information) |
Файл добавлен локально | Pending add into version control | |
File added to version control by another user | Pending add into version control | |
File is checked out by you | Проверенный локально | |
File is checked out by another user | Проверенный удалённо | |
There has been a conflict merging this file | Необходимо решить | |
Файл был удалён вами | Pending deletion in version control | |
File has been deleted by another user | Pending deletion in version control | |
Файл ещё не в системе контроля версий | n/a | |
Файл заблокирован вами | Не может быть изменено другими пользователями | |
Файл заблокирован другим пользователем | Не может быть изменено вами | |
Другой пользователь отметился в новой версии данного файла | Чтобы получить последнюю версию, используйте опцию “применять входящие изменения” (“Apply Incoming Changes”) | |
The server is requesting the version control status of this file, or is waiting for a response | You can only see this when using a centralised version control system like Perforce |
Вещи, которые стоит отметить:
When working with assets, Unity automatically checks out both the asset file as well as the associated .meta file. In most situations however, the .meta file is not modified, which might cause some extra work e.g. when merging branches at a later point.
Unity поддерживает работу в оффлайне, т.е. чтобы можно было продолжить работу с вашим депозиторием контроля версий без подключения к сети.
Unity supports asynchronous version control status queries for some version control providers, such as Perforce. This option allows those providers to update the version control status of files without stalling Unity. Use this option when the connection to your version control server has high latency.
Note: Only status queries are asynchronous. Operations that change the state of files, or require up-to-date knowledge of file status, are performed synchronously.
If Unity cannot commit your changes to your version control client, (for example, if the server is down or license issues occur), your changes are stored in a separate changeset.
To learn more about working with the Asset Server (Unity’s internal version control system), see documentation on the Asset Server.
To work with a version control system unsupported by Unity, select MetaData as the Mode for Version Control in the Editor window. This allows you to manage the source Assets and metadata for those Assets with a version control system of your choice. For more on this, see documentation on External Version Control Systems.
2017–02–12 Page amended with limited editorial review
Documentation on asynchronous version control status queries added in Unity 2017.3.