简体   繁体   中英

How do I ignore a certain file type in a certain directory and its sub-directory in Git?

How can I ignore a certain filetype only in one directory and its sub-directory?

To explain what I mean imaging the following setup

  • anotherdir/
    • seeme1.iml
  • foldertoignore/
    • ignoreme1.iml
    • seeme3.txt
    • anotherignorefolder/
      • ignoreme2.iml
      • seeme4.txt
  • seeme5.iml

I want to be able to do is tell git (using .gitignore file) to ignore *.iml but only under the directory foldtertoignore .

I was thinking this would work

foldertoignore/*.iml

But that only found ignoreme1.iml not ignoreme2.iml

I know how to tell it to ignore *.iml except for a specific directory. This is the reverse of that. Any thoughts?

.gitignore rules are applied recursively from the containing directory. Simply create the file foldertoignore/.gitignore with *.iml as contents.

>>foldertoignore/.gitignore echo '*.iml'
git add foldertoignore/.gitignore
git commit -m 'Ignore .iml files in foldertoignore and its subfolders'

You can try this:

/foldertoignore/**/*.iml

It may or may not work depending on fnmatch implementation in your OS I suppose. Alternative is:

*.iml
!/anotherdir/*.iml
!/*.iml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM