2

Unity3D 入门:Unity 项目版本管理建议使用的 .gitignore 忽略文件和 .gitattributes...

 3 years ago
source link: https://blog.walterlv.com/post/unity-starter-git-ignore-and-git-attributes.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Unity3D 入门:Unity 项目版本管理建议使用的 .gitignore 忽略文件和 .gitattributes 文件(2020年4月更新)

发布于 2020-04-29 17:41
更新于 2020-06-01 01:21

Unity3D 项目虽然说使用 C# 脚本开发,但毕竟不是 .NET/C# 项目。今天一位小伙伴告诉我说用错了 .gitignore 文件,结果管理仓库时丢了很多重要的文件。


实际上,GitHub 官方提供了大量不同项目类型的 .gitignore 文件,并且有广大的社区支持时时更新,直接前往 GitHub 官网下载是最好的选择了。

适用于 Unity 项目的 .gitignore 模板:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

注意到 sln 和 csproj 都是忽略的文件吗?这是 Unity 的项目,其他 .NET 项目经常使用的 sln 解决方案管理方式在这里只是辅助手段而已,你可以阅读我的另一篇博客了解更多:

额外的,你可能注意到 Unity 项目里面有大量的 *.meta 文件,是自动生成的,这个要加入到版本管理吗?答案是需要。Unity 创建这些文件是为了给导入的文件添加额外的元数据信息的,毕竟不能直接修改原来的文件。这些信息包含:

  • 描述如何导入这个资产文件
  • 如何在项目中准备资产

如果你删除了这些文件,那么 Unity 会用默认的元数据信息生成一个对应的 .meta 文件。

其他类型的 .gitignore 文件前往 GitHub 的 gitignore 仓库:

另外,开启一个新的 Unity 项目时,放一个适用于大多数场景的 .gitattributes 也可以一开始规避一些坑。你可以从下面这位大佬拿到他整理的一个 .gitattribute 文件。


参考资料

本文会经常更新,请阅读原文: https://blog.walterlv.com/post/unity-starter-git-ignore-and-git-attributes.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,或者前往 CSDN 关注我的主页

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名 吕毅 (包含链接: https://blog.walterlv.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 ([email protected])


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK