1

I have question regarding ignore and exclude rules in .gitignore.

So I have a very large file tree where I want to ignore all lib files except a specific lib file which is a text file with a .lib extension:

What I have in my .gitignore file:

# exclude rule
!text.lib
# ignore rule
*.lib

However, I can not see all the text.lib files in my file tree when issuing a git status. The '!text.lib' is overrulled by *.lib'

How to make a rule that can solve this?

Thank you very much:-)

2 Answers2

1

If you want to reinclude a pattern which was ignored before you have to specify it after the pattern which ignores it.

From the gitignore documentation:

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.

So your ignore file has to look like this:

*.lib
!text.lib

Hope that helps!

Sascha Wolf
  • 18,810
  • 4
  • 51
  • 73
0

Please check the answer for this stackoverflow question. .gitignore exclude folder but include specific subfolder

You will just need to change expressions.

Community
  • 1
  • 1
Özgür Eroğlu
  • 1,230
  • 10
  • 16
  • Thank you for your answer. The problem is that the files are spread all over a large file tree. So far, I have different versions of test.lib placed in over 50 different directories. So I would really prefer a generic rule, rather that having to specify a exclude rule for every directory containing a test.lib file. Am I missing something? – Peter Dalgaard Hansen Jul 08 '14 at 10:00