Search code examples
gitvisual-studio-codegitignore

Cannot include a file from an excluded directory with .gitignore on Vs Code


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 ?


Solution

  • 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