Search code examples
windowsgitvisual-studio-codegitignore

Git still tracks files in gitignore file


i am having the following problem with gitignore in windows (that i used in combination with vscode, if this info is important)

i tried a simple example in order not to complicate things.

my root folder contains:

maininterface.py
.gitignore
logs/dev.log

my gitignore file has only one line:

logs/

when typing git status i get the following:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        logs/
        maininterface.py

Am I missing something? the directory logs should not be in the untracked files.
I tried looking for solutions, many people suggest git rm --cached logs This does not work for me, I get :

fatal: pathspec 'logs' did not match any files 

(I also tried git rm --cached logs/dev.log , same problem)

BTW I haven't used git add on any of the files.

Thank you if you have a tip...


Solution

  • Check if your .gitignore file is free of parasite characters.

    For example : a BOM at the beginning of the file would make git try to look for "{\xEF\xBB\xBF}logs".


    [edit] : I had forgotten powershell writes in UTF-16 (or UCS-2) by default, you correctly found that, on top of a BOM, your file was actually encoded in UCS-2.