首页 > 解决方案 > Unity .gitignore 不忽略 .asset 文件

问题描述

我目前正在尝试阻止对我的 git 版本控制的更改,这些更改处理某个文件夹中的 .asset 文件。即使我输入以下行,.asset 文件及其关联的 .meta 文件也会添加到提交中。我什至尝试阻止该数据所在的特定文件夹,但它仍然会推送。我想知道 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/
[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

# SongPong Specific ___CUSTOM___
*.swp
*.asset
#Ignore all .meta file
*.meta
#But not source file with postfix. which is everything but a folder
!*.*.meta

此外,如果有人使用任何更好/更新的 gitignore 来统一,我也将不胜感激

标签: gitunity3dgitignore

解决方案


请记住,gitignore 不会神奇地从以前的提交中删除文件。

至于为什么还要添加资产,我找不到问题来源。如果元文件有前缀或在 内,则仍会添加您的元文件/[Aa]ssets/**/,基于此行:

!/[Aa]ssets/**/*.meta

此外,您应该始终推送与项目中文件关联的元文件!如果您不这样做并且其他人拉取该项目,那么新的唯一元文件也将在另一个项目中创建。现在你们都有不匹配的元文件,这意味着您的“指针”不再同步,您将遇到缺少参考的问题。想象一下,有人创建了一个预制件并在检查器的某个公共字段中引用它,然后推送该更改。你拉它,但引用的 ID 不存在,因为你的同一个文件的元文件有不同的 ID。因此,您突然得到一个缺少的参考,并且该文件不再位于该公共字段中。


推荐阅读