在Unity 3D中使用Git源代码控制的最佳实践是什么,特别是在处理Unity 3D项目的二进制性质时?请描述工作流程,在.gitignore中包含哪些路径,应该在Unity和/或项目中设置什么设置,以及任何其他应该注意的特殊事情。

注意:我知道使用资产服务器是unity推荐的方式,但出于各种原因,我想使用Git。请不要回答,状态或争论,我应该只是使用资产服务器。资产服务器真的不是我的选择。


当前回答

在使用git进行unity-3d源代码版本控制时,需要记住的主要事情:

(A)不要签入图书馆文件夹。我在过去犯过很多次这样的错误,并为此付出了代价! 在将项目/文件添加到git之前,删除或移出库文件夹。

(B)使用“可见元文件”-对于最新的unity版本- 5.3.4及以上默认发生。对于一些早期版本,您需要更改下面的设置: 编辑->项目设置->版本控制

(C)为Unity使用.gitignore文件-以确保保持正常,并且不会不必要地添加文件-如果在android / tizen上-添加规则以排除APK和TPK文件添加到存储库。 或者使用GitHub提供的。gitignore for unity模型: https://github.com/github/gitignore/blob/master/Unity.gitignore

(D)确保.gitignore文件作为第一个添加的文件添加到存储库中——因为在过去我个人没有添加过。gitignore文件。事后有很多关于为什么会发生这种情况的想法-但现在我只是复制并添加.gitignore文件作为设置存储库的第一步。

所以…为git准备一个Unity项目,执行以下步骤:

(1)进入项目文件夹

(2)类型 Git初始化。

复制.gitignore文件: MacOS系统:cp ~/Downloads/.gitignore 在Windows下:复制c:\Users[yourusername]\Downloads。gitignore。

添加 .gitignore (4)

前往添加 (5) *

希望这对你有所帮助……祝你一切顺利!

其他回答

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与Github到unity扩展… https://unity.github.com/

新的GitHub for Unity扩展带来了GitHub工作流和更多的Unity,提供支持大文件与Git LFS和文件锁定。

在撰写本文时,该项目仍处于alpha阶段,但仍可用于个人项目。

只是补充一下吉提诺的主题。 推荐的方法只忽略Library和Temp,如果它在你的git项目的根目录内。如果你像我一样,有时需要统一项目成为回购的一部分,而不是整个回购,gitignore中正确的字符串将是:

**/[Tt]emp
**/[Ll]ibrary
**/[Bb]uild

我和我的朋友在72小时的游戏jam中尝试过这种方法,请注意他们不知道GIT。

首先,我在[GitHub][1](私人回购现在是免费的)与预定义的.gitignore统一模板创建空回购,它应该与此相同:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

Then I've created a main scene, this scene shouldn't be modified by any individual while they are development, It should be the demo scene for all dev and artists in the team to test the latest features in game. First of all any new feature should be in a separate branch from main, also each team member has his own scene that he use it for testing and development. once everything is good he/she made a PR reviewed by other members. If the merged feature is complete then we add it to the main scene so that all other members see the impact and the progress.

关于美术文件,最好是通过精灵文件的变化来避免冲突,并将主要精灵替换为pr中完全调整过的新精灵。 [1]: https://github.com/

以下是我个人博客的节选。

使用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拉/合并之后,它都会查看哪些文件被删除了,检查文件所在的目录是否为空,如果是,就删除它。