Reputation: 521
I have a directory in VS Code which is excluded with .gitignore
.
Let's name this directory txt_files
.
In this directory i have a file which i would like to be included in my git thought. Let's name this file file.txt
This is what's my .gitignore
file looks like.
#ignore /venv files
/venv
#ignore vscode files
.vscode
# txt_files_folder
/txt_files
# include this file
!/txt_files/file.txt
but when i hit git status
i get no updates to add /txt_files/file.txt
.
What am i doing wrong ?
Upvotes: 0
Views: 218
Reputation: 13387
If it is a singular exception that you want to track txt_files/file.txt
, it is sufficient to
git add -f txt_files/file.txt
once. Thereafter, it will be tracked and any changes you make to the file will be detected.
(If you do not have a command line to do that, you can remove /txt_files
from .gitignore
temporarily until you have added the file.)
If it can happen repeatedly, or there is a pattern of files that you want to add, you better follow @code_fodder's answer.
Upvotes: 0
Reputation: 16331
To ignore a folder you do folder/
but this will ignore everything within and not allow for exclusions. So what you need to do there is:
# Ignore things within txt_files (not txt_files itself)
txt_files/*
# But not file.txt.
!txt_files/file.txt
if you do the entire folder it means its children also get excluded regardless of exclusions
Upvotes: 1