11

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?

SimonTheSorcerer
  • 500
  • 4
  • 13

4 Answers4

12

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
Community
  • 1
  • 1
Lawrence McAlpin
  • 2,745
  • 20
  • 24
  • By checking in .gitignore as you describe and pointed out in my question you do indirectly check in data about files which are generated by Maven. – SimonTheSorcerer Nov 17 '11 at 16:53
  • 4
    You're seriously over thinking this. My point is you don't want to check in anything generated by Maven. (Also, my .gitignore is not generated by Maven.) There is nothing wrong with putting in IDE specific files, output folders, and anything else you don't want checked in inside the .gitignore file. That is, in fact, the entire point of it. – Lawrence McAlpin Nov 17 '11 at 17:05
  • However, if you really don't want to have IDE or Maven-specific exclusions in the .gitignore, maybe you could try putting in negated entries to specify only what you DO want checked in. I've never done this myself, but you would put * in the .gitignore to ignore everything, and then add lines that start with ! to list exceptions [meaning those entries DO get checked in.] http://stackoverflow.com/questions/1279533/is-there-a-way-to-tell-git-to-only-include-certain-files-instead-of-ignoring-cer – Lawrence McAlpin Nov 17 '11 at 17:08
  • 1
    I will choose this answer and change my .gitignore to something like the following: `* !src !pom.xml !.gitignore` – SimonTheSorcerer Nov 18 '11 at 10:18
  • (Correcting the above) I will choose this answer and change my .gitignore to something like the following: `* !src !pom.xml !.gitignore` (sorry for missing line breaks). I want to reason why: **1.** The initial `.gitignore` file is simple and generic for every used IDE. **2.** The possibility of committing IDE-specific files is ruled out, no developer needs needs to hassle around with `.gitignore` for his favourite IDE. **3.** Clarifies what belongs to the repository. – SimonTheSorcerer Nov 18 '11 at 10:25
  • 1
    I don't know if this has changed since the original answer was given, but as of this comment in order for any subfolders to be unexcluded (for example a `src` folder) you need to start the file with `/*` instead of just `*`. So for example: `/* !.gitignore !build.gradle !src/` – nerdherd May 12 '14 at 15:18
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

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
Chanoch
  • 563
  • 7
  • 16
1

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
*~
Mohamed Ragab
  • 539
  • 3
  • 7
  • Can you provide such a template .gitignore? – SimonTheSorcerer Nov 17 '11 at 16:56
  • Thank you. Compared to the accepted answer your .gitignore looks more complex and more maintenance required. Just imagine a new IDE is supported by Maven and you need to modify all .gitignores of all projects in all branches etc. for the developers using it. – SimonTheSorcerer Nov 18 '11 at 10:28
0

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?

Grim
  • 1,938
  • 10
  • 56
  • 123
  • 1
    I have never heard of versioning **and** ignoring a file. What kind of effect does this have? – SimonTheSorcerer Nov 17 '11 at 16:57
  • I don't think that versioning settings helps anyone. Depending on the plugins you use, there could be any content (caches, machine or even file system dependent things, ...), so I would ignore that all of the time. I want eclipse to manage these, and yes, I need a way to recreate them. – mliebelt Nov 18 '11 at 06:46
  • @SimonTheSorcerer You can force to Download once, and never upload. This practice is used to tell newcommers what a binding a project need. Those Newcommers will not be able to commit their configurations! – Grim Nov 21 '11 at 11:22
  • @PeterRader I think that is a different use case but also an answer for another issue I had (I suppose for changing this "newcomer"-template you temporarely need to change .gitignore). So thank you for pointing this out. – SimonTheSorcerer Nov 21 '11 at 12:46
  • @PeterRader I tried this and unfortunately this does not work out. Git asks whether to commit an ignored AND versioned file, if it changes. But this is off topic, where do I find information about this? – SimonTheSorcerer Dec 12 '11 at 14:50