1

I want to create a custom Unity package, but since I want to work on it I want to check in a whole Unity project instead of just pushing the required package files.

So normally all packages are exluced via

[Pp]ackages/

I tried this

.gitignore exclude folder but include specific subfolder

![Pp]ackages/
[Pp]ackages/**
![Pp]ackages/BroadcastCore/

and this almost seems to work. Unfortunately it tries to include the manifest.json and packages-lock.json in the Packages directory. How can I just include all the files from the BroadcastCore directory?

This is a screenshot when changing the lines from

# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/

to

[Pp]ackages/

in the .gitignore

enter image description here

Now I updated the single line with the three lines. Here you can see that it tries to include the files from the Packages directory but I think those files shouldn't exist in the remote repository

enter image description here

Question3r
  • 2,166
  • 19
  • 100
  • 200

1 Answers1

1

If it tries to include files in a folder which is supposed to be ignored, that means those files are probably already tracked.

Check this with:

git check-ignore -v -- Packages/manifest.json

If it returns nothing, it is not ignored in the first place.

Try the same command after:

git rm --cached -- Packages/manifest.json

See if removing the tracked file from Git index is enough.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • tested with `[Pp]ackages/` only: The second command results in a not found error. The first one returns this `.gitignore:485:[Pp]ackages/ Packages/manifest.json` – Question3r Jun 27 '21 at 10:44
  • tested with my new 3 lines: The second command results in a not found error. The first one returns this `.gitignore:482:[Pp]ackages/** Packages/manifest.json` – Question3r Jun 27 '21 at 10:45
  • So it seems this file gets ignored but unfortunately it still tries to add it to the repository – Question3r Jun 27 '21 at 10:46
  • @Question3r "Unfortunately it tries to include the manifest.json and packages-lock.json in the Packages directory. ": can you share in your question a screenshot of "it" trying to include those files? – VonC Jun 27 '21 at 11:00
  • @Question3r Can you double-check with a `git status`, in command line, at the root folder of your repository? Do you see `Packages/manifest.json`? And would a `git check-ignore -v -- Packages/manifest.json` still display a `.gitignore` rule then? – VonC Jun 27 '21 at 13:44