【问题标题】:Unity Gitignore not ignoring binary filesUnity Gitignore 不忽略二进制文件
【发布时间】:2021-09-09 20:34:22
【问题描述】:

我的 Multiplayer Unity 游戏项目(由单个存储库中的游戏服务器和客户端项目组成)中的 .gitignore 文件有问题。 .gitignore 文件会忽略大部分文件,但不会忽略库工件中的二进制文件。 Image of binary files showing in Github Desktop.

我知道 .gitignore 文件有效,因为如果我将其删除,则有 30000 个更改的文件和 8000 个未删除的文件。

# 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
*.aab
*.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/*

Image of the repository folder with the 2 projects

【问题讨论】:

    标签: unity3d github repository


    【解决方案1】:

    呵呵,我想你的答案在.gitignore的第一行

    这个 .gitignore 文件应该放在你的 Unity 项目目录的根目录下

    所有那些前面没有/ 的忽略路径仅与.gitignore 的位置相关。它是这样工作的:

    将忽略:

    • ./Build/myBinary

    不会忽略:

    • ./project1/Build/myBinary
    • ./project2/Build/myBinary

    最简单的解决方案是复制您的 .gitignore 并将其中一个放在每个 项目目录 的根目录中,而不是 repo 目录。

    您的目录应如下所示:

    • 我的回购
      • 项目1
        • .gitignore
        • 资产
        • ...
      • 项目2
        • .gitignore
        • 资产
        • ...

    如前所述,如果这些目录中的文件已经提交,则需要手动删除它们。

    【讨论】:

    • 我已将 gitignore 文件复制到项目文件夹中,但文件仍然显示在 git 状态中
    • gitignore 仅适用于尚未跟踪的文件。试试这个:1.删除文件(原始的gitignore就位),2.git add . && git commit,3.将重复的gitignores放在正确的位置,4.git status
    • 通过删除文件是像删除库文件夹还是什么? (对不起,我是使用存储库的新手)
    • 是的,没错,也许先做一个备份:)
    • 感谢您的建议。库文件现在按预期被忽略。
    【解决方案2】:

    为了确定,假设此文件夹中只有二进制文件,请尝试删除它们(仅从 Git 索引中,而不是从您的磁盘中),并立即检查(无需提交)您的 .gitignore 是否适用。

    cd /path/to/repo
    git rm -r --cached path/to/folder/with/binaries/ # note the trailing slash
    
    git check-ignore -v path/to/folder/with/binaries/aBinary # must be a file
    

    如果最后一条命令没有返回任何内容,则不适用 .gitignore 规则。

    【讨论】:

    • 最后一个命令返回了 .gitignore:5:[Ll]ibrary/ 但文件仍然显示在 github 桌面上。
    • @JaydenKusuma 如果您执行git status,它们还会显示吗? (假设您确实从索引中删除了文件夹内容)
    • 它们仍然显示在 git 状态。我尝试按照上面的建议执行 git rm -r --cached 但它返回了一个'​​致命:pathspec'library'没有匹配任何文件'
    • @JaydenKusuma 您是否在可以看到子文件夹library 的文件夹中? (使用 git 大小写,因为它可能区分大小写)。
    • 是的,我的统一项目中有文件夹库,并且已经导航到那里
    猜你喜欢
    • 1970-01-01
    • 2014-07-06
    • 2022-11-16
    • 2019-04-29
    • 2018-05-02
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多