How to ignore IDE settings on Git?

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?


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.


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, eg 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.

链接地址: http://www.djcxy.com/p/6176.html

上一篇: 缓存和“删除”状态

下一篇: 如何忽略Git上的IDE设置?