1.首先是.gitignore的配置。
# Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Windows Installer files *.cab *.msi *.msm *.msp # Windows shortcuts *.lnk ### Unity ### /[Ll]ibrary/ /[Tt]emp/ /[Oo]bj/ /[Bb]uild/ /[Bb]uilds/ /Assets/AssetStoreTools* # Folders designed to be part of repository, but not their content /_NonVersioned/* !/_NonVersioned/README.md /Assets/_NonVersioned/* !/Assets/_NonVersioned/README.md !/Assets/_NonVersioned/README.md.meta !/Assets/_NonVersioned.meta /Builds/* !/Builds/README.md # Files to be excluded ## Files generated by Visual Studio / MonoDevelop ExportedObj/ obj/ *.svd *.userprefs /*.csproj *.pidb *.suo /*.sln *.user *.unityproj *.booproj # Unity3D generated meta files *.pidb.meta ## Files generated by OS .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes ehthumbs.db Thumbs.db # Unity3D Generated File On Crash Reports sysinfo.txt # Builds *.apk *.unitypackage
2.然后是.gitattributes的配置(所有工程最开始就应该做好这两步)。
* text=auto # keep lf on unity files *.asset text eol=lf *.meta text eol=lf *.prefab text eol=lf *.unity text eol=lf
3.在菜单Edit > Project Settings > Editor中打开Inspector,将Asset Serialization部分的Mode改成Force Text。
4.在SourceTree中设置如下选择 工具->选项->比较->外部差异对比合并->自定义->
对比命令如下:D:Program FilesUnityEditorDataToolsUnityYAMLMerge.exe(找到自己电脑中UnityYAMLMerge.exe的路径) 参数如下:merge -p $BASE $REMOTE $LOCAL $MERGED
5.在UnityYAMLMerge.exe所在的路径,找到mergespecfile.txt文件,修改合并命令。
此项根据自己的需求修改,可以用下面推荐的N种方式。
修改之前的合并命令如下:
unity use "%programs%YouFallbackMergeToolForScenesHere.exe" "%l" "%r" "%b" "%d"
prefab use "%programs%YouFallbackMergeToolForPrefabsHere.exe" "%l" "%r" "%b" "%d"
修改之后的命令如下:
#Araxis Merge
unity use "%programs%AraxisAraxis Mergecompare.exe" /3 /a2 /wait /title1:"Other" /title2:"Base" /title3:"Local" "%l" "%b" "%r" "%d"
prefab use "%programs%AraxisAraxis Mergecompare.exe" /3 /a2 /wait /title1:"Other" /title2:"Base" /title3:"Local" "%l" "%b" "%r" "%d"
#Beyond Compare 4
unity use "%programs%Beyond Compare 4comp.exe" "%l" "%b" "%r" "%d"
prefab use "%programs%Beyond Compare 4comp.exe" "%l" "%b" "%r" "%d"
6.合并说明:通常情况下第一栏是local分支,第二栏是base分支,第三栏是remote分支。