I'm trying to configure a .gitignore
file such that all files with a certain extension are ignored, except where they appear within a specific folder, or any sub folder of that folder. I've tried the following which does not work:
*.lib
!Libraries/
A second question I have is, do negated exclusions only apply to the immediately preceding rule, or do every rule you've defined up to that point?-
This almost answers my question, but doesn't help for sub folders.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
I think what you meant is ignore all *.lib
except when they're inside /Libraries
, try this out:
# The root directory's .gitignore
*.lib
!/Libraries/*.lib
# The .gitignore under /Libraries directory
!*.lib
The .gitignore
is parsed from top to bottom. Any rule can override prior rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With