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

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


当前回答

什么是GIT?

Git是一个免费的开源分布式版本控制系统(SCM),由Linus Torvalds于2005年(Linux操作系统的创始人)开发。它的创建是为了控制从小到大的项目的速度和效率。谷歌、Facebook、微软等领先公司每天都在使用GIT。

如果你想了解更多关于GIT的知识,请查看这个快速教程,

首先,确保已经设置好Git环境。您需要设置本地环境和Git存储库(我更喜欢Github.com)。

GIT客户端应用程序Mac/Windows

对于GIT gui客户端应用程序,我建议你去Github.com,

GitHub是一个可以与朋友、同事、同学和完全陌生的人分享代码的地方。超过500万人使用GitHub一起创建令人惊叹的东西。

Unity3d设置

你需要做这些设置

切换到“编辑→项目设置→编辑器→版本控制模式”中的“可见元文件”。

在Unity中启用外部选项→Preferences→Packages→Repository

在“编辑→项目设置→编辑器→资产序列化模式”中切换到“强制文本”。

来源: 使用Git与3D游戏源代码控制

其他回答

我和我的朋友在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进行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) *

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

我想添加一个非常简单的工作流程,它来自于曾经对git感到沮丧的人。git有几种使用方式,可能最常见的unity是GitHub Desktop, git Bash和GitHub unity

https://assetstore.unity.com/packages/tools/version - control/github -团结- 118069。

本质上它们都做同样的事情,只是用户的选择不同。你可以使用git进行大文件设置,它允许1GB的免费大文件存储,额外的存储可用在数据包中,每月4美元为50GB,这将允许你将文件>100mb推到远程存储库(它将实际文件存储在服务器上和你的repo指针中)

https://git-lfs.github.com/

如果你不想安装lfs,不管什么原因,你可以扫描你的项目文件> 128mb在windows通过键入大小:大在你有你的项目的目录。这对于搜索大文件非常方便,尽管可能会漏掉一些100mb到128mb之间的文件。

git bash的一般格式是

Git添加。(添加要提交的文件)

Git commit -m 'message'(提交带有消息的文件,它们仍然在你的PC上,而不是在远程repo中,基本上它们已经被“版本化”为新的提交)

Git推送(将文件推送到存储库)

git bash对于unity项目的缺点是,如果有一个> 100mb的文件,你不会得到一个错误,直到你推送。然后,您必须通过将头部重置到上一次提交来撤销您的提交。有点麻烦,特别是如果你是git bash的新手。

GitHub桌面的优势是,在你提交100mb的文件之前,它会给你一个弹出的错误消息。然后可以收缩这些文件或将它们添加到.gitignore文件中。

要使用.gitignore文件,请在本地存储库根目录中创建一个名为.gitignore的文件。只需一次一行地添加您想要省略的文件。SharedAssets和其他非资产文件夹文件通常可以省略,并将自动在编辑器中重新填充(包可以重新导入等)。您还可以使用通配符来排除文件类型。

如果其他人正在使用你的GitHub回购,你想克隆或拉你有这些选项可供你以及在GitHub桌面或Git bash。

我没有提到太多关于Unity GitHub包,你可以在编辑器中使用GitHub,因为我个人认为界面不是很有用,我不认为总体上它会帮助任何人熟悉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项目置于源代码控制之下的信息,你可以在这篇文章中找到。