How to Include and Exclude files using .gitignore file ?
Why gitignore not working ?
Ignore files and folders using .gitignore
Example 1. Ignore (Exclude) a simple file or a folder
sites/default/settings.php
sites/*/files
Example 2. Include a file / folder
!sites/default/testfile.php
!sites/*/testfolder
Example 2. Include a file located in a Excluded folder
Step 1. Include the 'Excluded' folder
!sites/*/files
Step 2. Exclude All files and folders in this folder
sites/*/files/*
Step 3. Re Include the specific file or folder
!sites/default/files/my_included_file.pdf
Git Cache : gitignore not working
If files are already cached, .gitignore may not working
Solutions.
CAUTION !!! Do not forget to commit your changes before all this operations
1. Rebuild all cache
git rm -r --cached .
git add .
git commit -m "clear all cache to fix file tracking"
2. Remove cache of a folder already added to the git
git rm -r --cached thefile.txt thefolder
3 Remove cache of a file already added to the git
git rm --cached sites/default/settings.php
Note
The file .gitignore is versioned by git. If you don't want to version ignored files list, you can also "EXCLUDE" file which is located on .git/info/exclude .
Comments