如何为 git 准备 Unity 项目? [英] How to prepare a Unity project for git?

查看:43
本文介绍了如何为 git 准备 Unity 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

准备将 Unity 项目提交到 git 存储库所需的步骤是什么,例如.github?我不想存储不必要的文件(特别是临时文件并尽可能避免二进制格式).

What are the steps necessary to prepare a Unity project for committing to a git repository eg. github? I don't want to store unnecessary files (specially temp files and avoid binary formats as much as possible).

推荐答案

在 Unity 编辑器上打开您的项目并:

On the Unity Editor open your project and:

  1. Unity 中启用 外部选项首选项存储库(仅当 Unity 版本 <4.5)
  2. 编辑项目设置编辑器版本控制模式中切换到可见元文件
  3. 编辑项目设置编辑器资产序列化模式<中切换到强制文本/strong>
  4. 文件菜单保存场景和项目.
  5. 退出Unity,然后您可以删除项目目录中的LibraryTemp 目录.您可以删除所有内容,但保留 AssetsProjectSettings 目录.
  1. Enable External option in UnityPreferencesPackagesRepository (only if Unity ver < 4.5)
  2. Switch to Visible Meta Files in EditProject SettingsEditorVersion Control Mode
  3. Switch to Force Text in EditProject SettingsEditorAsset Serialization Mode
  4. Save Scene and Project from File menu.
  5. Quit Unity and then you can delete the Library and Temp directory in the project directory. You can delete everything but keep the Assets and ProjectSettings directory.

如果您已经在线创建了空的 git 存储库(例如 github.com),现在是时候上传您的代码了.打开命令提示符并按照以下步骤操作:

If you already created your empty git repo on-line (eg. github.com) now it's time to upload your code. Open a command prompt and follow the next steps:

cd to/your/unity/project/folder

git init

git add *

git commit -m "First commit"

git remote add origin git@github.com:username/project.git

git push -u origin master

您现在应该在按住 Option 或左 Alt 键的同时打开您的 Unity 项目.这将强制 Unity 重新创建 Library 目录(这一步可能没有必要,因为我已经看到即使您没有按住任何键,Unity 也会重新创建 Library 目录).

You should now open your Unity project while holding down the Option or the Left Alt key. This will force Unity to recreate the Library directory (this step might not be necessary since I've seen Unity recreating the Library directory even if you don't hold down any key).

最后让 git 忽略 Library 和 Temp 目录,这样它们就不会被推送到服务器.将它们添加到 .gitignore 文件并将忽略推送到服务器.请记住,您只会提交 Assets 和 ProjectSettings 目录.

Finally have git ignore the Library and Temp directories so that they won’t be pushed to the server. Add them to the .gitignore file and push the ignore to the server. Remember that you'll only commit the Assets and ProjectSettings directories.

这是我自己的 Unity 项目的 .gitignore 配方:

And here's my own .gitignore recipe for my Unity projects:

# =============== #
# Unity generated #
# =============== #
Temp/
Obj/
UnityGenerated/
Library/
Assets/AssetStoreTools*

# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
*.svd
*.userprefs
*.csproj
*.pidb
*.suo
*.sln
*.user
*.unityproj
*.booproj

# ============ #
# OS generated #
# ============ #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

这篇关于如何为 git 准备 Unity 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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