I have created a white-list for text files only.
* !*.txt
Now, I have an untracked text file in a sub-directory - sub/dir/file.txt
, and this is NOT shown (it is ignored). Text files in the root directory are shown, however.
Why is that, and how do I fix it?
git. Git uses this special subdirectory to store all the information about the project, including all files and sub-directories located within the project's directory. If we ever delete the . git subdirectory, we will lose the project's history. Next, we will change the default branch to be called main .
gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
It will add all the Folders , Subfolders and files to the existing repo.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
If you try it that way, it'll fail, because you'll end up blacklisting the directories in your structure.
To solve, you want to blacklist everything that is not a directory, and is not one of the file-types you want to commit, while not blacklisting directories.
The .gitignore
file that will do this:
# First, ignore everything * # Now, whitelist anything that's a directory !*/ # And all the file types you're interested in. !*.one !*.two !*.etc
Tested this in a three-level structure white-listing for .txt
files in the presence of *.one
, *.two
and *.three
files using a .gitignore
located in the root directory of the repository - works for me. You won't have to add .gitignore
files to all directories in your structure.
Information I used to figure out the answer came from, amongst other things, this (stackoverflow.com).
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