With the .gitignore file we can tell Git to ignore certain types of files (like *.exe) or whole folders. All it takes is an entry like this if we want to ignore the folder database:
1 |
/database |
As explained in another post, we can ignore the .gitignore by putting a ! in front of the entry. To keep the file /database/create.sql, we create an entry like this:
1 2 3 |
# too greedy, does not work as expected /database !/database/create.sql |
Unfortunately, Git still ignores our create.sql file. It took me a while to figure out that the problem is not in the line with create.sql, but with the database folder. We must append /* to the folder name so that Git can ignore everything inside the folder but keeps the file create.sql:
1 2 3 |
# the /* is important! /database/* !/database/create.sql |
With this syntax you can add all the files you want to keep in Git while ignoring everything else in a folder.