17

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182

3 Answers3

21

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.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • @Holf The `file.f` doesn't work, because you reference file itself, without path (and you probably don't have `file.f` in your project's root folder). That's why _unutbu_'s answer have all examples with full path. The `*file.f` works, because you used `*` wildcard and thus it will ignore _any file_, that matches your pattern -- is it really, what you wanted to achieve? – trejder Feb 06 '14 at 10:17
5

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

cclaudiu
  • 51
  • 1
  • 2
0

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
petrsyn
  • 5,054
  • 3
  • 45
  • 48