如何使用 Git 进行 Unity3D 源代码管理? [英] How to use Git for Unity3D source control?

查看:115
本文介绍了如何使用 Git 进行 Unity3D 源代码管理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What are best practices for using Git source 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.

注意:我意识到使用 Asset Server 是 Unity 推荐的方式,但出于各种原因我想使用 Git.请不要回答说或争辩说我应该只使用资产服务器.Asset Server 真的不是我的选择.

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.

推荐答案

以下摘自 我的个人博客.

2015 年 10 月更新:此后,GitHub 发布了一个名为 Git LFS<的 Git 插件/a> 直接处理下面的问题.您现在可以轻松有效地对大型二进制文件进行版本控制!

Update Oct 2015: GitHub has since released a plugin for Git called Git LFS that directly deals with the below problem. You can now easily and efficiently version large binary files!

Git 可以很好地处理开箱即用的 3D 游戏.然而,这里的主要警告是,随着提交历史记录膨胀,从长远来看,对大型(> 5 MB)媒体文件进行版本控制可能是一个问题.我们仅在二进制资产被认为是最终版本时对其进行版本控制,从而解决了我们项目中的这个潜在问题.我们的 3D 艺术家使用 Dropbox 来处理 WIP 资产,出于上述和因为它更快、更简单(没有多少艺术家会积极地想要使用 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 Dropbox to work on WIP assets, both for the reason above and because it's much faster and simpler (not many artists will actively want to use Git!).

您的 Git 工作流程非常需要您根据自己的团队经验以及合作方式自行决定.然而.我强烈推荐适当命名的 Git Flow 方法作为此处由原作者描述.

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 Flow methodology as described by the original author here.

我不会在这里过多深入介绍该方法的工作原理,因为作者完美地描述了它,而且用的字数也很少,因此很容易理解.我已经和我的团队一起使用了一段时间,这是迄今为止我们尝试过的最好的工作流程.

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 或是否完全使用 GUI 方面有很多选择.但我想推荐免费的 SourceTree 应用程序,因为它与 Git Flow 扩展插件完美结合.在此处阅读 SourceTree 教程 在他们的应用程序中实施 Git Flow 方法.

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 application as it plugs in perfectly with the Git Flow extension. Read the SourceTree tutorial here on implementing the Git Flow methodology in their application.

查看最新版本 Github 维护的 Unity.gitignore 文件 没有操作系统细节.

For an up to date version checkout Github maintained Unity.gitignore file without OS specifics.

# =============== #
# 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 及更高版本:

Unity3D Settings

For versions of Unity 3D v4.3 and up:

  1. (在 v4.5 及更高版本中跳过此步骤)在 Unity → Preferences → Packages → Repository 中启用 External 选项.
  2. 打开Edit 菜单并选择Project Settings → Editor:
  1. (Skip this step in v4.5 and up) Enable External option in Unity → Preferences → Packages → Repository.
  2. Open the Edit menu and pick Project Settings → Editor:
  1. 版本控制模式切换到可见元文件.
  2. 资产序列化模式切换为强制文本.
  1. Switch Version Control Mode to Visible Meta Files.
  2. Switch Asset Serialization Mode to Force Text.

  • File 菜单保存场景和项目.
  • Save the scene and project from File menu.
  • <小时>

    是否要将现有的存储库迁移到 LFS?

    查看我的博客文章,了解如何在此处执行操作的步骤 .

    在 Unity3D 项目中使用 Git 的少数主要烦恼之一是 Git 不关心目录,并且在从目录中删除文件后会很高兴地留下空目录.Unity3D 会为这些目录生成 *.meta 文件,当 Git 提交不断添加和删除这些元文件时,可能会导致团队成员之间发生一些争执.

    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 合并后挂钩添加到 /.git/hooks/ 文件夹中包含 Unity3D 项目的存储库.任何 Git pull/merge 之后,它都会查看删除了哪些文件,检查它所在的目录是否为空,如果是则将其删除.

    Add this Git post-merge hook to 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 进行 Unity3D 源代码管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆