My .gitignore
file seems to be being ignored by Git - could the .gitignore
file be corrupt? Which file format, locale or culture does Git expect?
All the answers here are actually workarounds. You need to create the .gitignore file before you run git init
. Otherwise git
will never know you need to ignore those files, because they have been tracked already.
echo .idea/ >> .gitignore
git init
If you develop on a daily basis, I advise you to add your habitual ignored files to your ~/.gitignore_global
file. That way, git
will already know which files you (meaning "your user", since it's a file in your home directory) usually ignore.
I've created .gitignore using echo "..." > .gitignore
in PowerShell in Windows, because it does not let me to create it in Windows Explorer.
The problem in my case was the encoding of the created file, and the problem was solved after I changed it to ANSI.
It is also a possibility that you edited the .gitignore
file with a sudo
command. I encountered the same issue and while executing the commands: git status
, I could still see the "should be ignored" files.
Upon editing with nano .gitignore
instead of sudo nano .gitignore
, I could see the correct reflection.
There's another issue with .gitignore
that might happen, especially for a Windows user. Git does not like it when you name .gitignore
(such as unity.gitignore
).
You'll want to always name it .gitignore
, or on Windows, .gitignore.
as Windows thinks you are trying to rename it without a filename.
I noticed that the encoding of the .gitignore
was having an effect--if the file was Unicode, it was ignored, if it was ASCII, it wasn't.
Process:
PS> git status
.gitignore
's encoding: PS> Get-FileEncoding .gitignore
PS> Set-Content .gitignore -Encoding Ascii -Value (Get-Content .gitignore)
PS> git status
Also check out the directory where you put .gitignore
.
It should be in the root of your project:
./myproject/.gitignore
Not in
./myproject/.git/.gitignore