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?
One tricky thing not covered by the other answers here is that the .gitignore file won't work if you have inline comments, like this:
foo/bar # The bar file contains sensitive data so we don't want to make this public
So, if you do have comments like that, change them like this:
# The bar file contains sensitive data so we don't want to make this public
foo/bar
My issue was (as OP suggested) a corrupt .gitignore file. I didn't believe that it was and ignored the possibility until everything else failed. The corruption didn't show up in vi
, but there were two bytes on the start of the file that caused the .gitignore file to be ignored. For me, these only showed up when I typed cat .gitignore
, which showed:
��# Built application files
*.apk
*.ap_
# ...
I have no idea how these ended up there, but recreating the file fixed the issue. A hex analysis of the corrupt file showed the following:
user@dev ~/project/myproject $ xxd -b .gitignore
00000000: 11111111 11111110 00100011 00000000 00100000 00000000 ..#. .
00000006: 01000010 00000000 01110101 00000000 01101001 00000000 B.u.i.
Fixed. OK, I created the .gitignore file in Notepad on Windows and it wasn't working. When I viewed the .gitignore file on Linux it looked like organised gibberish - perhaps Notepad had written out Unicode rather than ASCII or whatever 8-bit is.
So I rewrote the file on my Linux box, and when I pulled it back into Windows it works fine! Hurrah!
My problem was that I wrote down files to ignore with quotes " " separation not with slash /.
This did not work and was ignored by git :
"db.sqlite3"
"tdd_venv/"
This worked just fine :
/db.sqlite3
/tdd_venv/
I also checked my file encoding in windows with Notepad++. Encoding was set to UTF-8.
I too have the same issue on Ubuntu, I created the .gitignore
from the terminal and it works for me
touch .gitignore
If you are a Notepad++ user, try doing the following:
Open your .gitignore file using Notepad++ and do:
Menu Edit → EOL Conversion → Windows Format → Save.
Try using git status
again and see if it works for you.
I have posted the answer to a similar question here.