4

I have some entries in my .gitignore file in my git repository but some of the entries still show up as untracked files.

The important parts from my .gitignore file:

# IDE settings
.idea/

# Environments
win_venv/

# Byte-compiled / optimized / DLL files
__pycache__/

# Distribution / packaging
*.egg-info/

However, when I run git status, this shows up:

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

        .idea/
        mypackage.egg-info/
        mypackage/__pycache__/
        mypackage/schema/__pycache__/
        mypackage/schema/models/__pycache__/
        mypackage/tests/__pycache__/
        win_venv/

Anyone knows, why this can happen or what the mistakes in my .gitignore file are?

This question is different to the answer suggested, as shown files are not tracked. This issue also happens, if I create a new virtual environment venv, having the appropriate entry in the .gitignore file.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33

4 Answers4

5

This was a tricky one and another proof, that git works better on Linux. The problem in this very specific case was, that the file encoding was not properly set, so the .gitignore file was handled as a binary file.

Thank you @LeGEC for pointing me into the right direction: I figured out, that something is wicked, when I did a cat .gitignore on a WSL console and the content looked something like this:

    I D E   s e t t i n g s
 . i d e a /

 #   B y t e - c o m p i l e d   /   o p t i m i z e d   /   D L L   f i l e s
 _ _ p y c a c h e _ _ /

AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33
  • 1
    As you discovered, Git does not understand Windows UTF-16 encodings. (This is true for other files as well—UTF-16 encodings will result in Git thinking they are binary...) – torek Jul 21 '20 at 14:11
  • (facepalm) nice catch @AnsFourtyTwo – LeGEC Jul 21 '20 at 15:47
2

(not an answer, just a list of suggestions to further debug the issue)

Try running git status from different shells : cmd.exe, powershell, git-bash and see if the behavior is the same in all three.

You can also see more information with the following commands :

git status --ignored

git check-ignore -v [paths]
# 'check-ignore' only checks paths explicitly listed on the command line :
git check-ignore -v *
git check-ignore -v .idea mypackage.egg-info mypackage/__pycache__

more details in this question : Git command to show which specific files are ignored by .gitignore

Finally : you can also run git add .idea/ (perhaps choose the folder with the least files ?) and see what gets added.
You can revert that using git reset .idea/

LeGEC
  • 46,477
  • 5
  • 57
  • 104
1

Simply delete the current .gitignore file and then create it as a txt file then rename it to .gitignore. This happens in windows only

0

Sometimes when you add files/folders to .gitignore then these files/folders will still be present in your repository index.

Follow steps to get rid of it:

Step 1 . First committed all your changes, including your .gitignore file

Step 2. Remove or clear your repo, use below command including dot [.]

git rm -r --cached . 

Your repository is clean and git status should not show untracked file now

The . indicates that all files will be untracked

--cached will only remove files from the index

Step 3. Re add everything & commit

 git commit -a -m ".gitignore fix"

Your repository is clean and git status should not show untracked folders

Priyesh
  • 501
  • 3
  • 12
  • Thanks for your answer. But, actually this is not the problem in my case. Files were definitely not added and therefore shown as untracked files. – AnsFourtyTwo Jul 26 '20 at 20:09