Search code examples
gitgithubversion-control

Why is .gitignore not tracking a file despite using the ! notation


I have the following in my .gitignore:

data/
!data/data_file.csv

yet the data_file.csv is not being tracked and I get the following when I check the ignore rules:

 git check-ignore -v data/data_file.csv  
.gitignore:2:data/      data/data_file.csv

I have tried

git rm -r -f --cached .
git add -A
git commit -m "Some commit message"

Can anyone explain why this is and ho to get the file to be tracked?


Solution

  • You don't want to ignore the entire folder, merely its contents.
    That will allow you to un-ignore the content item(s) of your choice.

    data/*
    !data/data_file.csv