I have a project with directory uploads/ which has subdirectories /images and /files. I want to ignore commiting files from these two subdirectories uploads/images and uploads/files but i want .gitignore file to be in root directory.
1 Answer
Simply add in the .gitignore:
/uploads/images/ /uploads/files/ That will ignore the content of those folders, provided they were not already versioned.
If they were, you would need to remove them from the index and commit (recording the deletion from the repo, not from the disk: --cached)
git rm -r --cached uploads/images git rm -r --cached uploads/files but this ignore even the folders, not only content, I want to ignore only content of those folders
One trick is to ignore the all folder (as described above), and then do:
touch uploads/images/.keep git add --force uploads/images/.keep touch uploads/files/.keep git add --force uploads/files/.keep git commit -m "keep fodlers" That means you need to have some content in order to keep the folder in the repo (an empty folder would not be tracked by Git).
3 Comments
PYovchevski
but this ignore even the folders, not only content, I want to ignore only content of those folders
Biffen
@PYovchevski Git doesn't track directories. At all. Ever.
VonC
@PYovchevskiI have edited the answer in order to keep the folder while ignoring their content
.gitignorethen. What is the problem, exactly?