Just had a similar problem and realized: The files were already added and checked in to git.
How to recognize the difference: Git didn't show the files as "new", but as "modified". This details has cost me quite some time...
If that is the problem, simply "git rm" these files and start over. Suddenly, .gitignore starts to work as expected.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…