1

I've created .gitignore file to ignore eclipse files, it looks like this:

target
.classpath
.project
.settings/

The problem is that git status still shows me that those files can be added to stage:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .classpath
#       .project
#       .settings/
nothing added to commit but untracked files present (use "git add" to track)

Any idea why? BTW I'm new git user, I work on Windows.

pepuch
  • 6,346
  • 7
  • 51
  • 84

2 Answers2

4

Even though you've added them to your .gitignore, sometimes Git will not ignore them once it already knows about them. You can fix it by executing these:

git rm -r --cached .
git add .
git commit -m "Ignore eclipse files"
blacktide
  • 10,654
  • 8
  • 33
  • 53
  • After calling `git add .`, command `git status` is showing that ignored files has been added to stage. Is it ok? – pepuch Nov 27 '13 at 19:34
  • That shouldn't happen. Are you writing your `.gitignore` file using Notepad by chance? – blacktide Nov 28 '13 at 00:16
  • Yes. The problem may occurs because of windows style new lines? – pepuch Nov 28 '13 at 05:08
  • 1
    Yes, I do believe so. Try saving it in another text editor such as Notepad++, or saving it specifically using ANSI encoding in Notepad. [This answer](http://stackoverflow.com/a/11451916/2446208) may be useful for you. – blacktide Nov 28 '13 at 05:12
  • 1
    Problem finally solved. It was really stupid mistake :) I created my files not with notepad but from windows command line using `echo` command, for example `echo .classpath >> .gitignore`. And where is the problem? SPACE between `.classpath` and `>>`. I didn't see that these spaces were added to `.gitignore` at the end of each line. I've also changed line endings to unix style. @caseyscarborough you helped me a lot! – pepuch Nov 28 '13 at 16:38
  • Very interesting problem! Glad you got it all figured out. – blacktide Nov 28 '13 at 17:04
0

If you have made the same mistake as me and @pepuch with echo ignoreme >> .gitignore, and this time with powershell, it's possible for the encoding to be incorrect also (mine was set to UTF-16BOM according to notepad++), so make sure that it uses UTF-8.

micsthepick
  • 562
  • 7
  • 23