Git not excluding even untracked files

90 Views Asked by At

I am running into a problem with git. I have initialized a new git repo and wrote ".gitignore" first but git is not excluding those files and folders. I have tried "git rm -r --cached" and then added only .gitignore file but it all went in vain. [screenshot of IDE]

Tried unstaging the files but as you can see in the screenshot, git status is still showing the .venv and pycache folder that should be excluded in the untracked section.

2

There are 2 best solutions below

1
Muhammad Zeeshan On BEST ANSWER

As suggested by @j6t , UTF-16 encoding for .gitignore will not work. So, save it as UTF-8 and the problem will be gone. If you run into the same problem then before following any other procedures make sure correct encoding has been selected while saving the file.

1
amphetamachine On

Git ignore lists can have !<pattern> lines that undo or add an exception to an ignore pattern that was previously set.

For example:

# mydir/.gitignore
# Ignore everything in this directory
*
# Except this file
!.gitignore

Git loads its ignore list from (highest precedence to lowest):

  1. Patterns specified on the command line.
  2. Whatever core.excludesFile is set to, by default $XDG_CONFIG_HOME/git/ignore aka ~/.config/git/ignore
  3. .git/info/exclude
  4. <current directory>/.gitignore

I would check:

  1. Is there a .venv/.gitignore file that contains some exclusion lines?
  2. Is there an exclusion line later on in the root-level .gitignore file that mentions !.venv or !/.venv?