How to ignore IDE settings on Git? - eclipse

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

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

Related

gitignore > some ignored files still added to the repository

I don't understand why ignored files are still added to the repository. Are there some circumstances when files which are in the .gitignore list, can be still added to the repository
I added directory to the .gitignore before I did anything with the project (project is clean, no trucked or untracked files). Then I built the project. During the build process some files were modified. When the build was done, most of the modified files were ignored, but some were added to the repository. I don't understand this git's selectivity.
Usually, files are added to the index when modified if they were tracked before the .gitignore referenced them.
Try:
git rm --cached -r biz/modules/rest-apis/docs/refAddress
Then control that all files are ignored, by selecting one which was added before:
git check-ignore -v -- biz/modules/rest-apis/docs/refAddress/GET_1.0_v4_addresses.json
You should see a .gitignore rule (no output means: the file is not ignored).

.gitignore_global has no effect on .idea/ created by JetBrains

I am trying to get Git to ignore .idea/ created by JetBrains' product but somehow it works on every folder I created except the .idea/ created by JetBrains. Why ?
So how do I globally ignore .idea/ ?
I already had my core.excludesfile set to ~/.gitignore_global
Make sure first that folder was not already tracked:
cd /path/to/repo
git rm -r --cached .idea/
Then check your git status: add, commit (register the deletion): the .gitignore should now be in effect for that folder.
To check that the folder ignore rule is in effect:
git check-ignore -v -- .idea/a_file_inside_.idea_folder
As long as it returns nothing, that file (inside the .idea folder) is not ignored.
That git check-ignore command will consider all ignore files possible, including the core.excludesfile one (in your case set to ~/.gitignore_global)

Git commit shows changed files like metadata although they are in gitignore file

The information on the commits on GitHub says there are thousands of additions and deletions in files such as metadata even though the metadata is in the gitignore file.
This is how looks like my gitignore file:
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
.springBeans
You probably added certain files to .gitignore after they had already been tracked by git. If this is the case, you need to tell git to untrack the file:
git rm --cached <file>

Why is git still trying to add the classpath files?

I am working on a windows computer with cygwin using git with eclipse...
git keeps trying to add the following files
modified: EJB/.classpath
modified: WAR/.classpath
but if you look in my .gitignore it looks like this..
Flex/src/generated/
work/
logs/
build/
EJB/classes/
WAR/WebRoot/WEB-INF/classes/
.classpath
EJB/.classpath
com.genuitec.eclipse.persistence.jpa.prefs
WAR/.classpath
WAR/.classpath
EJB/.classpath
what else can I do or try?
I think you have added those .classpath files to git earlier, and git is already tracking them, so adding them to .gitignore is not sufficient.
You need to stop tracking it in your repo. Try
git rm -r --cached EJB/.classpath WAR/.classpath
git commit -m "untracking .classpath files"
And after this, gitignore will ignore the changes to them.

Git overriding .project file in eclipse

This is is a simple question. When I switch between branches my eclipse files get deleted in my project because they are not in my repository. .gitignore only works when checking in, not when switching branches. How can I keep my .project files in my project filed while using git?
Thanks
If a .project file was committed to the repository before it was added to .gitignore, it won't be ignored. You need to remove it from the repository. Since you probably want to keep it in your working tree, try this:
git rm --cached .project