Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore IDE settings on Git?

Tags:

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?

like image 584
Cataclysm Avatar asked Jul 05 '14 05:07

Cataclysm


People also ask

How do I ignore a .git folder?

A . gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track. Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder.

How do I ignore files in git ignore?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

What do I put in git ignore?

gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.

What is the command to ignore git?

There is no explicit git ignore command; instead, the . gitignore file must be edited and committed by hand when you have new files that you wish to ignore. The . gitignore files hold patterns that are matched against file names in your repository to determine whether or not they should be ignored.


2 Answers

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.

like image 125
VonC Avatar answered Oct 01 '22 13:10

VonC


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.

like image 37
user218867 Avatar answered Oct 01 '22 11:10

user218867