9

I have below Git information and I would like to ignore settings of my IDE (Eclipse).

modified:   myproject/.classpath
modified:   myproject/.project
modified:   myproject/.settings/com.google.gdt.eclipse.core.prefs
modified:   myproject/.settings/org.eclipse.core.resources.prefs
modified:   myproject/.settings/org.eclipse.jdt.core.prefs
modified:   myproject/.settings/org.eclipse.wst.common.component
modified:   myproject/.settings/org.eclipse.wst.common.project.facet.core.xml
modified:   myproject/.settings/org.eclipse.wst.validation.prefs

I tried the below statements in my .gitignore file, but it doesn't work for these settings:

.project
.classpath
.settings
*.project
*.classpath
*.settings
/.project
/.classpath
/.settings
.project/
.classpath/
.settings/
*.project/
*.classpath/
*.settings/

I am using Mac OS X and I also added global gitignore file with these settings git config --global core.excludesfile '~/.gitignore', but I'm still getting the above Git update messages when I check with git status. What am I wrong?

Cataclysm
  • 7,592
  • 21
  • 74
  • 123
  • Here is a book, you can refer to for any issue of git, if you didn't read yet: http://git-scm.com/book – Eric Jul 05 '14 at 06:22

3 Answers3

25

If those elements were already committed, you need to remove them first:

git rm --cached .project
git rm --cached .classpath
git rm --cached -r .settings

The --cached option allows them to stay in the working tree, while being recorded for deletion.
Once deleted, they will be ignored.

Once committed, the next changes will be ignored.

A simple .gitignore in myproject/ folder is enough:

.project
.classpath
.settings/

Note the / for .setting folder: that will ignore everything in it.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for fast response sir ! I didn't already commit sir. When I change eclipse settings or some of my maven configurations , these messages were appeared and I always checkout (`git checkout`) line by line . That very worse things for me. – Cataclysm Jul 05 '14 at 05:38
  • These files were not committed yet sir , if so how to do ? – Cataclysm Jul 05 '14 at 05:40
  • @Cataclysm are they added to the index? – VonC Jul 05 '14 at 05:40
  • @Cataclysm did you try a `git rm --cached .project` anyway, just to see of the 'modified' status disappeared? – VonC Jul 05 '14 at 05:41
  • sir , please don't be mind . I am still a beginner on using Git. I really don't know what is **index**. – Cataclysm Jul 05 '14 at 05:41
  • @Cataclysm I confirm: if you do a `git commit` now, the `.project` will then be ignored. If you do the other `git rm --cached` I suggested, and then commit, those other resources will be ignored. – VonC Jul 05 '14 at 05:45
  • sir now I didn't see them but I would like to know are they appear next time when I update settings ? – Cataclysm Jul 05 '14 at 05:50
  • @Cataclysm once removed and committed, any future change to those file will be ognored because of your `.gitignore` file. – VonC Jul 05 '14 at 05:50
  • sir ! now I am confuse . my `.gitignore` file ? am I need to add in `.gitignore` file also ? – Cataclysm Jul 05 '14 at 05:53
  • @Cataclysm yes, it is useful to add and commit the `.gitignore` file, as I mention in my edited answer. – VonC Jul 05 '14 at 05:54
  • If you add files (and not commit them), you have to remove them with git reset - http://stackoverflow.com/questions/348170/how-to-undo-git-add-before-commit . – Xdg Oct 07 '16 at 19:15
2

Following is my .gitignore config for a java web project:

*.class
*.swp
*.cache
*~

bin/**/*
target/**/*
build/**/*
gen/**/*

# tmp source folder
tmp/**/*


# js plugin
WebContent/js_plugin/lib/**/*

After git 1.8.2, If you want to ignore a folder named abc in any folder or subfolder, use following:

**/abc/**/*

So, I suggest you upgrade your git, if it's too old.

By the way, in my opinion, if team is using the same IDE, you should sync the .classpath things to git, ofcause, this is base on you have convention to name your jdk / tomcat / ... things like this. So that,once a jar is added via maven, all people get it after pull.
But, if you commit eclipse config, when push, make sure that change is useful, if not, don't commit, e.g. 2 source folder just change their line orders, in this case you can git checkout -- xxx, to ignore that change, so that won't effect other people.

Eric
  • 22,183
  • 20
  • 145
  • 196
0

It worked for me yeah but removing files from cache would be more helpful

#IDE files .gradle .idea idea-module-files *.iml com.springsource.sts.config.flow.prefs org.sonar.ide.eclipse.core.prefs

org.springframework.ide.eclipse.beans.core.prefs org.springframework.ide.eclipse.core.prefs .springBeans eclipsebin org.eclipse.jdt.core.prefs org.eclipse.jdt.ui.prefs

NPM packages

**/node_modules

Compiled class file

*.class

Test classes

**/testclasses

saurabhshcs
  • 797
  • 5
  • 6