1.建好Unity工程后,首先在工程根目录下建立.gitignore
文件,以便对unity的忽略文件进行限制
# ---> Unity
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*
# Visual Studio 2015 cache directory
/.vs/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
# Builds
*.apk
*.unitypackage
-
Unity工程设置
Editor > Project Settings > Editor
- 使用Unity SmartMerge:
原文在此:file:///D:/Program%20Files/UnityLTS/Editor/Data/Documentation/en/Manual/SmartMerge.html
将场景文件和Prefab文件序列化为yaml文本文件之后,仍然有可能会在合并时遇到产生冲突的情况。不过好在Unity在5.X版本之后已经提供了一个便于处理合并的工具,并且已经集成在Editor中。你可以在你的Unity安装目录下的Unity/Editor/Data/Tools文件夹中找到这个名为YAML Merge的工具。
也就是说,在工程根目录下建立.gitconfig
文件,然后把下面这段添加进去:
[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
注意上面的<path to UnityYAMLMerge>
就是unity提供的YAML Merge工具的位置,每个人是不同的;
团队协作,这个.gitconfig
文件肯定是要同步的,而每个人机器上这个工具的位置又不同,怎么解决这个问题?我的做法是把这个文件copy出来然后给每个成员发一份,让他们放在一个固定的位置,比如:D:\
。然后,在上面的文件中指定统一的位置:cmd = 'D:\\UnityYAMLMerge.exe' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
- 大文件(LFS)
众所周知git对大文件的支持是不大好的,在这里找到一个解决办法:
在工程目录下建立.gitattributes
文件,写入以下内容,当然,如果是自建Git服务器的话,需要服务器支持:
# 3D models
*.3dm filter=lfs diff=lfs merge=lfs -text
*.3ds filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.c4d filter=lfs diff=lfs merge=lfs -text
*.collada filter=lfs diff=lfs merge=lfs -text
*.dae filter=lfs diff=lfs merge=lfs -text
*.dxf filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.jas filter=lfs diff=lfs merge=lfs -text
*.lws filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
*.ma filter=lfs diff=lfs merge=lfs -text
*.max filter=lfs diff=lfs merge=lfs -text
*.mb filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text
*.ply filter=lfs diff=lfs merge=lfs -text
*.skp filter=lfs diff=lfs merge=lfs -text
*.stl filter=lfs diff=lfs merge=lfs -text
*.ztl filter=lfs diff=lfs merge=lfs -text
# Audio
*.aif filter=lfs diff=lfs merge=lfs -text
*.aiff filter=lfs diff=lfs merge=lfs -text
*.it filter=lfs diff=lfs merge=lfs -text
*.mod filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
*.s3m filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.xm filter=lfs diff=lfs merge=lfs -text
# Fonts
*.otf filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
# Images
*.bmp filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.hdr filter=lfs diff=lfs merge=lfs -text
*.iff filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.pict filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.tif filter=lfs diff=lfs merge=lfs -text
*.tiff filter=lfs diff=lfs merge=lfs -text
然后下载安装git,就可以开始搞了,连接到上次我们自建的git server,一切尽在掌控之中的感觉真好
work flow
个人觉得,小团队适合github flow
, 中到大型团队适合gitflow
, 我们放到第三部分再说这个问题吧