I have this file structure
aaafolder
└─ bbbfolder
├─ filename0.txt
├─ dddfolder
│ ├─ filename1.txt
│ └─ filename2.txt
├─ cccfolder
└─ filename.txt
I want all the contents of the aaafolder
folder to be hidden, but all files in the dddfolder
folder must be present.
So in the repository, I want to get in Git this:
aaafolder
└─ bbbfolder
└─ dddfolder
├─ filename1.txt
└─ filename2.txt
My .gitignore
looks like this:
/source/aaafolder/**
!/source/aaafolder/bbbfolder/dddfolder/*
However, the entire aaafolder
folder is ignored
An exclamation mark can be used to match any character except one from the specified set.
Check the file you're ignoring Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.
gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.
Per the gitignore
documentation, when negating:
it is not possible to re-include a file if a parent directory of that file is excluded.
This means that you'll need to ensure that the parent of dddfolder
is included, even if the contents of dddfolder
are not included.
In other words, you cannot use the **
to greedily match. You'll need to use a single-level wildcard. You'll need to exclude folders leading up to dddfolder
and then include their contents.
aaafolder/*
!aaafolder/bbbfolder
aaafolder/bbbfolder/*
!aaafolder/bbbfolder/dddfolder
Try it like this :
aaafolder/*
!aaafolder/bbbfolder/*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With