3

I have a new Git project in my Eclipse and the Staging View's Unstaged Changes panel shows not only the file I'm working on, but also .classpath and .project, while these are set to be ignored in Eclipse's Preferences > Team > Ignored Resources. How come?

NB: whether or not it's a good idea to ignore .classpath and .project is out of the scope of this question.

pHneutre
  • 1,091
  • 3
  • 12
  • 29

1 Answers1

1

while these are set to be ignored in Eclipse's Preferences > Team > Ignored Resources

This has nothing to do with Git or Git-related Eclipse views like Staging View's Unstaged Changes panel.

You would need to put those filenames into a .gitignore in order for them to not appear in that panel.

Then switch back to your Eclipse, and see if the Staging View's Unstaged Changes panel has still elements it should not display.

You can check if an untracked file is actually ignored with:

git check-ignore -v -- .classpath

Tihamer adds in the comments:

Switching back to Eclipse after editing the .gitignore file is not quite enough.
In the Git Staging view, you also need to hit the refresh button (upper right, just past the "filter files" textbox.

In my case, I checked out the documentation at git-scm.com/docs/gitignore and added "**target/**" (without quotes) using NotePad++.
After I hit the refresh button, the Git Staging showed exactly what it was supposed to (i.e. got rid of all the /target/ and .class files).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If they appear in the Unstaged Changes panel, it means they are not tracked though, doesn't it? And indeed your command gives `fatal: pathspec '.classpath' did not match any files`. – pHneutre Oct 10 '16 at 14:50
  • @pHCito Right! I have rewritten the answer. – VonC Oct 10 '16 at 14:58
  • So you are saying the Staging View (the only way to have the result of a `git status` in Egit) doesn't take into account the ignored resources setting of Eclipse, and more broadly, now that I think about it, that the ignored resources setting of Eclipse doesn't automatically set the `.gitignore` file. Alright, answer accepted. But why is it so in your opinion? – pHneutre Oct 10 '16 at 16:37
  • @pHCito The ignored resources setting of Eclipse predates by far the Egit integration. Those "ignored resources" are about the Eclipse **workspace** ([See here](http://stackoverflow.com/q/13552266/6309)), and are completely separate from the Git ignore mechanism. The staging view reflects the latter (which is what you see with Git alone), not the former (which exclusively depends on Eclipse, way before Eclipse had Git) – VonC Oct 10 '16 at 18:38
  • 1
    Switching back to Eclipse after editing the .gitignore file is not quite enough. In the Git Staging view, you also need to hit the refresh button (upper right, just past the "filter files" textbox. In my case, I checked out the documentation at https://git-scm.com/docs/gitignore and added "\*\*target/\*\*" (without quotes) using NotePad++. After I hit the refresh button, the Git Staging showed exactly what it was supposed to (i.e. got rid of all the /target/ and .class files). – Tihamer Jan 24 '19 at 15:49
  • @Tihamer Thank you. I have included your comment in the answer for more visibility. – VonC Jan 24 '19 at 16:38