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.

10
  • They have probably been added despite being in the ignore file. Commented Jul 21, 2020 at 11:14
  • Does this answer your question? How to make Git "forget" about a file that was tracked but is now in .gitignore? Commented Jul 21, 2020 at 11:15
  • 1
    I'm on Windows 10. Commented Jul 21, 2020 at 11:35
  • 1
    Probably a silly question, but where is your .gitignore located? Commented Jul 21, 2020 at 11:39
  • 1
    It is in a regular NTFS filesystem folder Commented Jul 21, 2020 at 11:59

4 Answers 4

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 _ _ / 
Sign up to request clarification or add additional context in comments.

2 Comments

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...)
(facepalm) nice catch @AnsFourtyTwo
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/

Comments

2

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

Comments

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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.