如何使用 Git 进行 Unity3D 源代码管理?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18225126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Git for Unity3D source control?
提问by PressingOnAlways
What are best practices for using Gitsource control with Unity 3D, particularly in dealing with the binary nature of Unity 3D projects? Please describe the workflow, what paths would be included in .gitignore, what settings should be set in Unity and/or the project, and any other special things that should be noted.
在 Unity 3D 中使用Git源代码控制的最佳实践是什么,尤其是在处理 Unity 3D 项目的二进制性质时?请描述工作流程,.gitignore 中将包含哪些路径,Unity 和/或项目中应设置哪些设置,以及任何其他应注意的特殊事项。
Note: I realize that using the Asset Server is the Unity-recommended way, but I would like to use Git for a variety of reasons. Please no answers that state or argue that I should just use the Asset Server. The Asset Server really isn't an option for me.
注意:我意识到使用 Asset Server 是 Unity 推荐的方式,但出于各种原因我想使用 Git。请不要回答说或争辩说我应该只使用资产服务器。资产服务器真的不是我的选择。
回答by S.Richmond
The following is an excerpt from my personal blog .
以下是我个人博客的节选。
Using Git with 3D Games
在 3D 游戏中使用 Git
Update Oct 2015:GitHub has since released a plugin for Git called Git LFSthat directly deals with the below problem. You can now easily and efficiently version large binary files!
2015 年 10 月更新:GitHub 此后发布了一个名为Git LFS 的Git 插件,该插件直接处理以下问题。您现在可以轻松有效地对大型二进制文件进行版本控制!
Git can work fine with 3D games out of the box. However the main caveat here is that versioning large (>5 MB) media files can be a problem over the long term as your commit history bloats. We have solved this potential issue in our projects by only versioning the binary asset when it is considered final. Our 3D artists use Dropboxto work on WIP assets, both for the reason above and because it's muchfaster and simpler (not many artists will actively want to use Git!).
Git 可以很好地处理开箱即用的 3D 游戏。然而,这里的主要警告是,随着提交历史记录膨胀,从长远来看,对大型(> 5 MB)媒体文件进行版本控制可能是一个问题。我们通过仅在二进制资产被认为是最终版本时对其进行版本控制,解决了我们项目中的这个潜在问题。我们的3D艺术家使用Dropbox的工作对WIP的资产,无论是上述的原因,因为它是很多更快和更简单(没有多少艺术家将积极想使用Git的!)。
Git Workflow
Git 工作流程
Your Git workflow is very much something you need to decide for yourself given your own experiences as a team and how you work together. However. I would strongly recommend the appropriately named Git Flowmethodology as described by the original author here.
您的 Git 工作流程非常需要您根据自己的团队经验以及合作方式自行决定。然而。我强烈推荐原作者在此处描述的适当命名的Git Flow方法。
I won't go into too much depth here on how the methodology works as the author describes it perfectly and in quite few words too so it's easy to get through. I have been using with my team for awhile now, and it's the best workflow we've tried so far.
我不会在这里深入探讨该方法是如何工作的,因为作者完美地描述了它,而且也用了很少的话,所以很容易理解。我已经和我的团队一起使用了一段时间,这是迄今为止我们尝试过的最好的工作流程。
Git GUI Client Application
Git GUI 客户端应用程序
This is really a personal preference here as there are quite a few options in terms of Git GUI or whether to use a GUI at all. But I would like to suggest the free SourceTree applicationas it plugs in perfectly with the Git Flow extension. Read the SourceTree tutorial hereon implementing the Git Flow methodology in their application.
这实际上是个人偏好,因为在 Git GUI 或是否完全使用 GUI 方面有很多选择。但我想推荐免费的SourceTree 应用程序,因为它与 Git Flow 扩展插件完美结合。在此处阅读有关在其应用程序中实施 Git Flow 方法的SourceTree 教程。
Unity3D Ignore Folders
Unity3D 忽略文件夹
For an up to date version checkout Github maintained Unity.gitignore filewithout OS specifics.
对于最新版本,请查看 Github 维护的 Unity.gitignore 文件,而没有操作系统细节。
# =============== #
# Unity generated #
# =============== #
Temp/
Library/
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Unity3D Settings
Unity3D 设置
For versions of Unity 3D v4.3 and up:
对于 Unity 3D v4.3 及更高版本:
- (Skip this step in v4.5 and up) Enable
External
option inUnity → Preferences → Packages → Repository
. - Open the
Edit
menu and pickProject Settings → Editor
:- Switch
Version Control Mode
toVisible Meta Files
. - Switch
Asset Serialization Mode
toForce Text
.
- Switch
- Save the scene and project from
File
menu.
- (在 v4.5 及更高版本中跳过此步骤)
External
在Unity → Preferences → Packages → Repository
. - 打开
Edit
菜单并选择Project Settings → Editor
:- 切换
Version Control Mode
到Visible Meta Files
。 - 切换
Asset Serialization Mode
到Force Text
。
- 切换
- 从
File
菜单中保存场景和项目。
Want you migrate your existing repo to LFS?
想要将现有的 repo 迁移到 LFS?
Check out my blog post for steps on how to do it here.
查看我的博客文章,了解如何在此处执行此操作的步骤。
Additional Configuration
附加配置
One of the few major annoyances one has with using Git with Unity3D projects is that Git doesn't care about directories and will happily leave empty directories around after removing files from them. Unity3D will make *.meta files for these directories and can cause a bit of a battle between team members when Git commits keep adding and removing these meta files.
将 Git 与 Unity3D 项目一起使用的少数主要烦恼之一是 Git 不关心目录,并且在从目录中删除文件后会很高兴地留下空目录。Unity3D 将为这些目录创建 *.meta 文件,并且当 Git 提交不断添加和删除这些元文件时,可能会导致团队成员之间发生一些争执。
Add this Git post-merge hookto the /.git/hooks/
folder for repositories with Unity3D projects in them. After any Git pull/merge, it will look at what files have been removed, check if the directory it existed in is empty, and if so delete it.
将此 Git 合并后挂钩添加到/.git/hooks/
包含 Unity3D 项目的存储库的文件夹中。在任何 Git pull/merge 之后,它会查看哪些文件已被删除,检查它所在的目录是否为空,如果是则将其删除。
回答by zasadnyy
In Unity 4.3 you also had to enable External option from preferences, but since Unity 4.5 they dropped option for that, so full setup process looks like:
在 Unity 4.3 中,您还必须从首选项中启用外部选项,但从 Unity 4.5 开始,他们放弃了该选项,因此完整的设置过程如下所示:
- Switch to
Visible Meta Files
inEditor → Project Settings → Editor → Version Control Mode
- Switch to
Force Text
inEditor → Project Settings → Editor → Asset Serialization Mode
- Save scene and project from
File
menu
- 切换到
Visible Meta Files
在Editor → Project Settings → Editor → Version Control Mode
- 切换到
Force Text
在Editor → Project Settings → Editor → Asset Serialization Mode
- 从
File
菜单保存场景和项目
Also our team is using a bit more extended .gitignore
file:
此外,我们的团队正在使用更多扩展.gitignore
文件:
# =============== #
# Unity generated #
# =============== #
Temp/
Library/
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
obj/
*.svd
*.userprefs
/*.csproj
*.pidb
*.suo
/*.sln
*.user
*.unityproj
*.booproj
# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Note that the only folders you need to keep under source control are Assets
and ProjectSettings
.
请注意,您需要保持在源代码控制之下的唯一文件夹是Assets
和ProjectSettings
。
More information about keeping Unity Project under source control you can find in this post.
有关将 Unity 项目置于源代码控制之下的更多信息,您可以在这篇文章中找到。
回答by NabeelSaleem
What is GIT?
什么是 GIT?
Git is a free and open source distributed version control system (SCM) developed by Linus Torvalds in 2005 ( Linux OS founder). It is created to control everything rom small to large projects with speed and efficiency. Leading companies like Google, Facebook, Microsoft uses GIT everyday.
Git 是由 Linus Torvalds(Linux OS 创始人)于 2005 年开发的免费开源分布式版本控制系统(SCM)。它旨在快速高效地控制从小到大的所有项目。谷歌、Facebook、微软等领先公司每天都在使用 GIT。
If you want to learn more about GIT check this Quick tutorial,
如果您想了解有关 GIT 的更多信息,请查看此快速教程,
First of all make sure you have your Git environment set up.You need to set up both your local environment and a Git repository (I prefer Github.com).
首先确保你已经设置了 Git 环境。你需要设置本地环境和 Git 存储库(我更喜欢 Github.com)。
GIT client application Mac/Windows
GIT 客户端应用程序 Mac/Windows
For GIT gui client application i recommended you to go with Github.com,
对于 GIT gui 客户端应用程序,我建议您使用 Github.com,
GitHub is the place to share code with friends, co-workers, classmates, and complete strangers. Over five million people use GitHub to build amazing things together.
GitHub 是与朋友、同事、同学和完全陌生的人共享代码的地方。超过 500 万人使用 GitHub 共同构建令人惊叹的事物。
Unity3d settings
Unity3d 设置
You need to do these settings
你需要做这些设置
Switch to Visible Meta Files in Edit → Project Settings → Editor → Version Control Mode.
在编辑 → 项目设置 → 编辑器 → 版本控制模式中切换到可见元文件。
Enable External option in Unity → Preferences → Packages → Repository
在 Unity → Preferences → Packages → Repository 中启用外部选项
Switch to Force Text in Edit → Project Settings → Editor → Asset Serialization Mode.
在 Edit → Project Settings → Editor → Asset Serialization Mode 中切换到 Force Text。
回答by rygo6
To add to everything stated, it is also ideal to use git lfswith Unity. I have been using this since it came out and I had no trouble with it.
为了补充说明的所有内容,将git lfs与 Unity一起使用也是理想的选择。自从它问世以来我一直在使用它,我没有遇到任何问题。
You will want to add this .gitattributes
next to your .gitignore
file
您需要将其添加.gitattributes
到您的.gitignore
文件旁边
*.cs diff=csharp text
*.cginc text
*.shader text
*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicsMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf
*.a filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.FBX filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
That is my rolling file list. If you use additional binary files not listed, add them.
那是我的滚动文件列表。如果您使用未列出的其他二进制文件,请添加它们。
I also have files configured to use yamlmerge, you would need to set this up. You can read about it here: http://docs.unity3d.com/Manual/SmartMerge.html
我也有配置为使用 yamlmerge 的文件,您需要进行设置。你可以在这里阅读:http: //docs.unity3d.com/Manual/SmartMerge.html
回答by Get Off My Lawn
I thought that I might post a simpler .gitignore
for anyone that is interested:
我想我可以.gitignore
为任何感兴趣的人发布一个更简单的:
# Ignore Everything
/*
# Except for these:
!/.gitignore
!/Assets
!/Packages
!/ProjectSettings
回答by Bhupen
We now have seamless integration to unity with Github to Unity extension... https://unity.github.com/
我们现在与 Github 到 Unity 扩展无缝集成到统一... https://unity.github.com/
The new GitHub for Unity extension brings the GitHub workflow and more to Unity, providing support for large files with Git LFS and file locking.
新的 GitHub for Unity 扩展为 Unity 带来了 GitHub 工作流和更多内容,通过 Git LFS 和文件锁定提供对大文件的支持。
At the time of writing the project is in alpha, but is still usable for personal projects.
在撰写本文时,该项目处于 alpha 阶段,但仍可用于个人项目。
回答by Naligator
The main things to remember when using git for unity-3d source code version control:
使用 git 进行 unity-3d 源代码版本控制时要记住的主要事项:
(A) DO NOTcheck-in the Library folder. I have made this mistake multiple times in past and have suffered for it! Delete OR move out library folder before adding your project / files into git.
(A)不要签入 Library 文件夹。我过去曾多次犯过这个错误,并为此受苦!在将项目/文件添加到 git 之前删除或移出库文件夹。
(B) Use "Visible Meta Files"- for newest unity versions - 5.3.4 and above this happens by default. For some of the earlier versions you need to change the settings under: Edit-> Project Settings-> Version Control
(B) 使用“可见元文件”- 对于最新的统一版本 - 5.3.4 及更高版本默认情况下会发生这种情况。对于某些早期版本,您需要更改以下设置:编辑-> 项目设置-> 版本控制
(C) Use a .gitignore file for Unity- to make sure sanity is maintained and files are not unnecessarily added- if on android / tizen - add rules to exclude APK and TPK files from being added to repository. Google around for a .gitignore file for unity OR else use this model .gitignore for Unity provided by GitHub: https://github.com/github/gitignore/blob/master/Unity.gitignore
(C) 为 Unity 使用 .gitignore 文件 - 以确保保持完整性并且不会不必要地添加文件- 如果在 android / tizen 上 - 添加规则以排除 APK 和 TPK 文件被添加到存储库。谷歌搜索统一的 .gitignore 文件,或者使用 GitHub 提供的这个模型 .gitignore for Unity:https: //github.com/github/gitignore/blob/master/Unity.gitignore
(D) Make sure the .gitignore file is added to the repository as the first file added - because in past I personally have missed adding .gitignore file.Have many thoughts in hindsight on why this happened- but nowadays I just copy and add .gitignore file as first step of setting up repository.
(D) 确保 .gitignore 文件作为添加的第一个文件添加到存储库中 - 因为过去我个人错过了添加 .gitignore 文件。事后有很多想法为什么会发生这种情况 - 但现在我只是复制并添加 .gitignore 文件作为设置存储库的第一步。
So... to make a Unity project ready for git, do the following:
所以……要为 git 准备一个 Unity 项目,请执行以下操作:
(1) Go to project folder
(1) 进入项目文件夹
(2) Type git init .
(2) 输入 git init 。
(3) Copy the .gitignore file: On MacOS: cp ~/Downloads/.gitignore On Windows: copy c:\Users[yourusername]\Downloads.gitignore .
(3) 复制 .gitignore 文件: 在 MacOS 上: cp ~/Downloads/.gitignore 在 Windows 上:复制 c:\Users[yourusername]\Downloads.gitignore 。
(4) git add .gitignore
(4) git add .gitignore
(5) git add *
(5) git 添加 *
Hope this helps... all the best!
希望这会有所帮助......一切顺利!
回答by Nipun David
I would rather prefer that you use BitBucket, as it is not public and there is an official tutorial by Unity on Bitbucket.
我宁愿您使用 BitBucket,因为它不是公开的,并且 Unity 有一个关于 Bitbucket 的官方教程。
https://unity3d.com/learn/tutorials/topics/cloud-build/creating-your-first-source-control-repository
https://unity3d.com/learn/tutorials/topics/cloud-build/creating-your-first-source-control-repository
hope this helps.
希望这可以帮助。
回答by Kyle B
You can use Github for Unity, a Unity Extensionthat brings the git workflow into the UI of Unity.
您可以使用Github for Unity,这是一个将 git 工作流带入 Unity UI 的 Unity扩展。
Github for Unityjust released version 1.0 of the extension.
Github for Unity刚刚发布了该扩展的 1.0 版。
- It uses git-lfs (git large file support) to properly store big assets
- File Locking so that nobody else overwrites your asset commits
- Push and Pull to/from anyremote repository
- You can also download it in the Unity Asset Store: https://assetstore.unity.com/packages/tools/version-control/github-for-unity-118069
- 它使用 git-lfs(git 大文件支持)来正确存储大资产
- 文件锁定,以便其他人不会覆盖您的资产提交
- 从任何远程存储库推送和拉取
- 也可以在Unity Asset Store下载:https: //assetstore.unity.com/packages/tools/version-control/github-for-unity-118069
回答by afpro
Edit -> Project Settings -> Editor
Edit -> Project Settings -> Editor
Set Version Control to meta files. Set Asset Serialization to force text.
将版本控制设置为元文件。设置资产序列化以强制文本。
I think this is what you want.
我想这就是你想要的。