Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore file types except within a specific folder (and all sub folders)?

Tags:

git

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.

like image 478
JBentley Avatar asked Mar 01 '13 05:03

JBentley


People also ask

How do I ignore a specific file type in git?

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.

Does Gitignore work in subfolders?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

How do you exclude or ignore some files from git commit?

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.


Video Answer


1 Answers

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.

like image 115
Tuxdude Avatar answered Sep 28 '22 09:09

Tuxdude