How to prepare a Unity project for git? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

This question already has an answer here:

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).

回答1:

On the Unity Editor open your project and:

  1. Enable External option in UnityPreferencesPackagesRepository (only if Unity ver
  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.

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 

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).

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.

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 


回答2:

Since Unity 4.3 you also have to enable External option from preferences, so full setup process looks like:

  1. Enable External option in Unity → Preferences → Packages → Repository
  2. Switch to Hidden Meta Files in Editor → Project Settings → Editor → Version Control Mode
  3. Switch to Force Text in Editor → Project Settings → Editor → Asset Serialization Mode
  4. Save scene and project from File menu

Note that the only folders you need to keep under source control are Assets and ProjectSettigns.

More information about keeping Unity Project under source control you can find in this post.



回答3:

@German As an extension to Germans answer: A new Unity project needs to be created in an empty folder. So you are not able to create your project to "where you have your local copy of the git repo" as mentioned in step 2. There is a workaround for this here: stackoverflow - git: clone into a not empty dir



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!