Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore is still not ignoring files despite removal

Tags:

git

gitlab

I know there are many, many posts on this topic. I've tried all of the answers I can find and none of them seem to be addressing my problem.

I started a git project where unfortunately .pyc files in __pycache__ directories were initially being tracked. I realised the problem and then put *.pyc and __pycache__ in .gitignore, but of course they were still being tracked.

I then:

  • Tried to remove the tracked files:

    git rm -r --cached .
    git add .
    git commit -m "fixed untracked files" 
    
  • Checked my .gitignore. The encoding, according to file -I .gitignore, is .gitignore: text/plain; charset=us-ascii. The .gitignore itself is:

    __pycache__
    *.pyc
    buildSite/.DS_Store
    *.DS_Store
    .idea/
    .idea/workspace.xml
    scratchFiles
    

    There aren't any extra whitespaces or anything.

I'm still getting .pyc files showing changes:

git status
...
modified:   buildSite/builder/templatetags/__pycache__/class_tag.cpython-36.pyc

Very grateful for any suggestions!

like image 544
user3757897 Avatar asked Feb 04 '26 07:02

user3757897


1 Answers

Make sure:

  • there is no crlf in your .gitignore file
  • there is no nested git repo (.git/ subolder) in any parent folder of your files to be ignored
  • there is a trailing / when ignoring a folder: __pycache__/, not __pycache__.
like image 65
VonC Avatar answered Feb 06 '26 00:02

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!