如何为 git 准备 Unity 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21573405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prepare a Unity project for git?
提问by German
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 项目以提交到 git 存储库所需的步骤是什么,例如。github?我不想存储不必要的文件(特别是临时文件并尽可能避免二进制格式)。
回答by German
On the Unity Editor open your project and:
在 Unity 编辑器上打开您的项目,然后:
- Enable External optionin Unity→ Preferences→ Packages→ Repository(only if Unity ver < 4.5)
- Switch to Visible Meta Filesin Edit→ Project Settings→ Editor→ Version Control Mode
- Switch to Force Textin Edit→ Project Settings→ Editor→ Asset Serialization Mode
- Save Scene and Project from Filemenu.
- Quit Unity and then you can delete the Libraryand Tempdirectory in the project directory. You can delete everything but keep the Assetsand ProjectSettingsdirectory.
- 在Unity→ Preferences→ Packages→ Repository 中启用外部选项(仅当 Unity ver < 4.5)
- 在编辑→项目设置→编辑器→版本控制模式中切换到可见元文件
- 在编辑→项目设置→编辑器→资产序列化模式中切换到强制文本
- 从文件菜单保存场景和项目。
- 退出Unity,然后您可以删除项目目录中的Library和Temp目录。您可以删除所有内容,但保留Assets和ProjectSettings目录。
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:
如果您已经在线(例如 github.com)创建了空的 git 存储库,现在是时候上传您的代码了。打开命令提示符并按照以下步骤操作:
cd to/your/unity/project/folder
git init
git add *
git commit -m "First commit"
git remote add origin [email protected]:username/project.git
git push -u origin master
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).
您现在应该在按住 Option 或左 Alt 键的同时打开您的 Unity 项目。这将强制 Unity 重新创建 Library 目录(这一步可能没有必要,因为我已经看到 Unity 重新创建 Library 目录,即使您没有按住任何键)。
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.
最后让 git 忽略 Library 和 Temp 目录,这样它们就不会被推送到服务器。将它们添加到 .gitignore 文件并将忽略推送到服务器。请记住,您将只提交 Assets 和 ProjectSettings 目录。
And here's my own .gitignore recipe for my Unity projects:
这是我自己的 Unity 项目的 .gitignore 配方:
# =============== #
# 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
回答by zasadnyy
Since Unity 4.3 you also have to enable External option from preferences, so full setup process looks like:
从 Unity 4.3 开始,您还必须从首选项中启用外部选项,因此完整的设置过程如下所示:
- Enable
External
option inUnity → Preferences → Packages → Repository
- Switch to
Hidden Meta Files
inEditor → Project Settings → Editor → Version Control Mode
- Switch to
Force Text
inEditor → Project Settings → Editor → Asset Serialization Mode
- Save scene and project from
File
menu
- 启用
External
选项Unity → Preferences → Packages → Repository
- 切换到
Hidden Meta Files
在Editor → Project Settings → Editor → Version Control Mode
- 切换到
Force Text
在Editor → Project Settings → Editor → Asset Serialization Mode
- 从
File
菜单保存场景和项目
Note that the only folders you need to keep under source control are Assets
and ProjectSettigns
.
请注意,您需要保持在源代码控制之下的唯一文件夹是Assets
和ProjectSettigns
。
More information about keeping Unity Project under source control you can find in this post.
有关将 Unity 项目置于源代码控制之下的更多信息,您可以在这篇文章中找到。