git ignore multiple matching files

I try to ignore file in a directory by relative path. E.g. I have several directories in working tree lib/file.f and I want all occurrences of this file to be ignored. I tried

lib/file.f

but this does not work.

  • how to use meld for reviewing remote changes. Using git as dvcs
  • Change the GIT root directory on a Windows computer
  • Is it right to use git cherry-pick in these scenarios?
  • git 'rebase' behaving differently to 'pull --rebase'
  • how does github 52 week participation work?
  • How to check if a repo exists?
  • Git: commit before merge?
  • Homebrew: how to use the formula from the pull request
  • Drupal Features Path To Module
  • failed when use “git remote add short_name url”
  • How to get a list of pull requests between 2 commits
  • Unable to acess - Push Git
  • 3 Solutions collect form web for “git ignore multiple matching files”

    Place

    */lib/file.f
    

    in your .gitignore. This will cause git to ignore any file of the form project/<DIR>/lib/file.f, assuming .gitignore is in the project directory.
    To make git ignore lib/file.f two directories down, you’d also have to add

    */*/lib/file.f
    

    to the .gitignore, and so on.

    Vastly simpler of course, would be to place

    *file.f
    

    in .gitignore to block all files named file.f, but your question seems to suggest there is at least one file by that name you wish not to ignore.

    also you might want to remove the file from git cache, in order to check what you just ignored:

    git rm --cached lib/file.f
    

    this is if you already added the file to git index

    If you want to specify all sub-folders under specific folder use /**/. To ignore all file.f files in a /src/main/ folder and sub-folders use:

    /src/main/**/file.f
    
    Git Baby is a git and github fan, let's start git clone.