Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 458
Lango Avatar asked Sep 28 '11 05:09

Lango


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 I ignore files in a folder in Git?

gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track. Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder.

How can I ignore particular file while doing commit?

Use an exclude file The exclude file lets Git know which untracked files to ignore and uses the same file search pattern syntax as a . gitignore file. Entries in an exclude file only apply to untracked files, and won't prevent Git from reporting changes to committed files that it already tracks.


1 Answers

.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'
like image 52
knittl Avatar answered Sep 28 '22 08:09

knittl