在Unity 3D中使用Git源代码控制的最佳实践是什么,特别是在处理Unity 3D项目的二进制性质时?请描述工作流程,在.gitignore中包含哪些路径,应该在Unity和/或项目中设置什么设置,以及任何其他应该注意的特殊事情。
注意:我知道使用资产服务器是unity推荐的方式,但出于各种原因,我想使用Git。请不要回答,状态或争论,我应该只是使用资产服务器。资产服务器真的不是我的选择。
在Unity 3D中使用Git源代码控制的最佳实践是什么,特别是在处理Unity 3D项目的二进制性质时?请描述工作流程,在.gitignore中包含哪些路径,应该在Unity和/或项目中设置什么设置,以及任何其他应该注意的特殊事情。
注意:我知道使用资产服务器是unity推荐的方式,但出于各种原因,我想使用Git。请不要回答,状态或争论,我应该只是使用资产服务器。资产服务器真的不是我的选择。
当前回答
I suggest that you make a .gitignore file that includes everything other than the assets folder (all the other files that are originally inside a unity project). Next, you should place all your game projects in one folder. Next, duplicate the .gitignore in every single project folder for your games. This will exclude the libraries and unnecessary folders inside your projects other than the assets. If you have any projects you don't want, then put them in a new .gitignore inside where your game projects are stored. Note: You can have multiple .gitignore's and .gitignore is based on relative paths. I hope that helped!
其他回答
在Unity 4.3中,你还必须从首选项中启用外部选项,但自从Unity 4.5以来,他们放弃了这个选项,所以完整的设置过程如下:
在编辑器→项目设置→编辑器→版本控制模式中切换到可见元文件 在编辑器→项目设置→编辑器→资产序列化模式中切换到强制文本 从文件菜单保存场景和项目
此外,我们的团队正在使用一些扩展的.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
注意,您需要保存在源代码控制下的文件夹只有Assets和ProjectSettings。
更多关于将Unity项目置于源代码控制之下的信息,你可以在这篇文章中找到。
以下是我个人博客的节选。
使用Git与3D游戏
2015年10月更新:GitHub已经发布了一个名为Git LFS的Git插件,直接处理以下问题。您现在可以轻松有效地版本大型二进制文件!
Git可以很好地处理3D游戏。然而,这里主要的警告是,版本控制大型(>5 MB)媒体文件可能是一个长期的问题,因为您的提交历史会膨胀。我们已经在我们的项目中解决了这个潜在的问题,只有在二进制资产被认为是最终的时候才对它进行版本控制。我们的3D美工使用Dropbox来处理在制品资产,既是出于上述原因,也是因为它更快更简单(没有多少美工会主动使用Git!)
总Workflow
你的Git工作流程需要你根据自己的团队经验以及如何一起工作来决定。然而。我强烈推荐原作者在这里描述的恰当命名为Git Flow的方法。
我不会在这里深入探讨这个方法是如何工作的,因为作者用很少的文字完美地描述了它,所以很容易理解。我和我的团队已经使用了一段时间了,这是我们迄今为止尝试过的最好的工作流程。
Git GUI客户端应用程序
这真的是个人偏好,因为在Git GUI方面有很多选择,或者是否使用GUI。但是我想推荐免费的SourceTree应用程序,因为它可以完美地插入Git Flow扩展。阅读SourceTree教程,在他们的应用程序中实现Git Flow方法。
Unity3D忽略文件夹
对于最新版本的结帐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设置
对于Unity 3D v4.3及以上版本:
(在v4.5及以上版本跳过此步骤)在Unity中启用外部选项→首选项→包→存储库。 打开编辑菜单,选择项目设置→编辑器: 切换版本控制模式为可见元文件。 将资产序列化模式切换为强制文本。 从文件菜单中保存场景和项目。
想要将现有的回购迁移到LFS?
请查看我的博客文章,了解如何做到这一点。
额外的配置
在Unity3D项目中使用Git的一个主要问题是Git不关心目录,并且在删除文件后会很高兴地留下空目录。Unity3D将生成*。当Git不断添加和删除这些元文件时,可能会导致团队成员之间的战斗。
将这个Git post-merge钩子添加到/。git/hooks/文件夹用于包含Unity3D项目的存储库。在任何Git拉/合并之后,它都会查看哪些文件被删除了,检查文件所在的目录是否为空,如果是,就删除它。
我们现在有无缝集成到unity与Github到unity扩展… https://unity.github.com/
新的GitHub for Unity扩展带来了GitHub工作流和更多的Unity,提供支持大文件与Git LFS和文件锁定。
在撰写本文时,该项目仍处于alpha阶段,但仍可用于个人项目。
I suggest that you make a .gitignore file that includes everything other than the assets folder (all the other files that are originally inside a unity project). Next, you should place all your game projects in one folder. Next, duplicate the .gitignore in every single project folder for your games. This will exclude the libraries and unnecessary folders inside your projects other than the assets. If you have any projects you don't want, then put them in a new .gitignore inside where your game projects are stored. Note: You can have multiple .gitignore's and .gitignore is based on relative paths. I hope that helped!
如果你使用源代码控制,确保你有一个git忽略无用的文件:https://github.com/github/gitignore/blob/main/Unity.gitignore