Should Eclipse-specific files in an VCS be ignored

2020-06-03 06:45发布

问题:

I know why not to commit Eclipse/IDE-specific files into a VCS like Git (which I am actually using). That is one of the reasons I am using Maven and having it generating these files for you and not having them under version control.

But I wonder, if these files should be ignored in .gitignore which itself is under control of VCS/Git:

.classpath
.project
.settings/
target/

Is this okay?

What are the pros and cons since the .gitignore file itself becomes kind of IDE-specific as the files ignored there are IDE-spefific? Any best-practice?

回答1:

With the team's I've worked on, the general rule has been that you don't check in anything that is generated by or obtained by Maven. Since the pom.xml contains everything you need to create the .project, .classpath, and .settings files, we don't check them in.

My .gitignore always contains .classpath, .settings, .project, and target for Maven projects.

Edit: As mentioned in my comment below, here is another suggestion: If you really want to avoid having Maven or IDE specific entries in your .gitignore, try writing your .gitignore so you list only what you DO want checked in.

*
!stuffIDoWantToCheckIn


回答2:

I'm getting my information from the following article: https://help.github.com/articles/ignoring-files

That suggests that you can create a global gitignore file (suggest under ~/.gitignore_global) containing .project, etc. As the file is outside the repo, it won't show...

You register it as a global ignore file with the following command:

git config --global core.excludesfile ~/.gitignore_global

Alternatively, you can create a per-repo untracked gitignore entries in the .git/info/exlude file



回答3:

I agree on not putting the IDE files under version control, this occasionally causes all sorts of pains, and as you mentioned using maven renders this unnecessary as any developer can simply import the project from the POM and get going

If these files are not put in the .gitignore they can easy be checked in by mistake

furthermore I do not find listing them in the .gitignore makes it IDE specific, you can list project files of eclipse, IntelliJ IDEA, and Netbeans, all in the same .gitignore if your team members use a mix of different IDEs. Over time you may accumulate a template .gitignore that ignores project files from all IDEs used in your team(s) to use whenever you create a new repository

If you are totally against putting these in the project .gitignore you can put them in the users .gitignore, but that in my mind is a bit looser as it depends on the individual development machines being configured correctly, and also these need to be maintained to be kept in sync with any new additions

Edit: I currently have an equivalent .hgignore, same concept different syntax, I converted it to git as an example of such a .gitignore file

/target/
/bin/
/build/
/.classpath
/.project
/.settings/
/.checkstyle
/atlassian-ide-plugin.xml
/.idea/
/*.iml
/*.ipr
/*.iws
*.orig
*.swp
*~


回答4:

usually .project and .settings/ should likley be versioned and ignored!

.classpath and target should not be versioned but ignored.

This is a first inital boot-up on checkout-practice.

i.e.

  • You told everone to use four spaces as tab, this information is stored under .settings/xxx
  • but you give no restriction where they have to install their tomcat/jdk's (stored under .classpath)

ok?