Unity Gitignore not ignoring binary files

Viewed 1266

I have a problem with the .gitignore file in my Multiplayer Unity game project (consists of a game server and a client project in a single repository). The .gitignore file ignores most of the files, but not the binary files from the library artifacts. Image of binary files showing in Github Desktop.

I know the .gitignore file works because if I remove it there is 30000 changed files and 8000 without removing it.

# 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

2 Answers

hehe i think your answer is on the first line of the .gitignore

This .gitignore file should be placed at the root of your Unity project directory

All of those ignore paths without a preceeding / are only relative to the location of the .gitignore. It works like so:

Will ignore:

  • ./Build/myBinary

Will not ignore:

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

Simplest solution is to duplicate your .gitignore and place one of each at the root of each project directory, not the repo directory.

Your directory should look like this:

  • myRepo
    • project1
      • .gitignore
      • Assets
      • ...
    • project2
      • .gitignore
      • Assets
      • ...

As mentioned, if files in these directories have already been committed they will need to be removed manually.

To be sure, assuming there are only binaries in this folders, try and delete them (from the Git index only, not from your disk), and check immediately (no commit needed) if your .gitignore applies.

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

If the last command does not return anything, then no .gitignore rule applies.

Related