I have a directory where I want to keep track of only a few files out of many.
The .gitignore
file would become unnecessarily long compared to a .gitnotice
.
Is it possible to tell git to ignore everything except the designated files?
Asked
Active
Viewed 58 times
3
-
Duplicate (https://stackoverflow.com/questions/6011521/opposite-of-gitignore-file), but I like the way you asked the question. – Lucas Charbonnier Jul 15 '20 at 13:28
1 Answers
6
You can use the !
character to negate patterns in .gitignore
. So, for example, you could ignore an entire directory other than a couple of specific files:
dir_to_ignore/*
!dir_to_ignore/file_you_want_to_track
!dir_to_ignore/another_file_you_want_to_track

Mureinik
- 297,002
- 52
- 306
- 350