189

What files/folders can I safely ignore for inclusion with git?

I copied a good project, removed its gen and bin folders and tried to run the app. The Android Launch window says, "Your project contains error(s), please fix them before running your application. There is a red X on the icon to the left of the project in the Package Explorer. While the gen folder does not exist in Windows Explorer, it does in Package Explorer.

Ian
  • 50,146
  • 13
  • 101
  • 111
user401120
  • 1,921
  • 2
  • 12
  • 5
  • 1
    Do a 'refresh' of the project (right click on project / refresh) or via Menu > Project > Clean project.. - that might help you get rid of the error messages in Eclipse. Sometimes only a Eclipse restart helps as well, unfortunately. Eclipse isn't very reliable, but a good free tool for the beginning. (I've already switched to IntelliJ IDEA myself. Much better, not free though.) – Mathias Conradt Jul 24 '10 at 15:57
  • http://www.gitignore.io/api/gradle,eclipse,android,ios,java,c,c++,objective-c – Jared Burrows Jun 16 '14 at 04:06

6 Answers6

261

There are file types to ignore

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

From Gitignore on github

Nate
  • 12,963
  • 4
  • 59
  • 80
Vik Gamov
  • 5,446
  • 1
  • 26
  • 46
  • 17
    In fact this has been updated on GitHub, it also includes amongst other things the `.project`, I disagree here and want your opinion. Scenario: I added new classes to my project. When I pulled from another machine, they were not in the project. Please check it out: https://github.com/github/gitignore/blob/master/Global/Eclipse.gitignore – Daniel Jul 07 '12 at 03:02
  • 16
    I agree with you @Daniel. I believe it is incorrect (as suggested in the .gitignore file you link to on GitHub) to exclude `.project`, `.classpath` and `.settings`. These are part of the project setup which you would like to capture in git. – mgd Dec 21 '12 at 07:58
  • 7
    From the Eclipse documentation: "[Make sure that the .project and .classpath files are under version control.](http://wiki.eclipse.org/FAQ_How_do_I_set_up_a_Java_project_to_share_in_a_repository%3F)" – D Krueger May 16 '14 at 19:01
33

What I usually add to .gitignore is:

bin
gen

bin and gen are constantly changed while coding, so there's no need to include them into the Git repository. Also, sometimes I add .classpath and .project which are Eclipse specific files, because maybe I want to create a new Android project based on these same sources, but in another OS or IDE.

With regards to the error, I would clean the project and/or try to run the Fix Project Properties utility (right-click on the Project -> Android Tools -> Fix Project Properties).

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • How about actually identifying and fixing the error? Why could cleaning the project do anything if it hasn't compiled yet? – Justin Buser Jul 15 '12 at 14:06
12

Best solution today is probably to generate the exact .gitignore file you need. Just go to http://www.gitignore.io

The project is also on Github: https://github.com/joeblau/gitignore.io

Diego Freniche
  • 5,225
  • 3
  • 32
  • 45
7

It's safe to ignore bin and gen, without problems. When I have problems with a project setup, I do this: First - have you looked at the 'Problems' tab in the view underneath the editor view - it generally gives more detailed information about project errors. If there's nothing conclusive there, I do the things below:

  1. Generally, when I'm having issues with Eclipse giving me phantom errors in the project, cleaning the project will fix it. It's in the menu, under Project>Clean.
  2. If that doesn't work, I'll usually try right clicking the project, going to Android Tools> Fix project properties.
  3. My last resort it to restart eclipse and delete the gen folder.
QRohlf
  • 2,795
  • 3
  • 24
  • 27
2

the best way is use this site to generate: http://www.gitignore.io/

LiangWang
  • 8,038
  • 8
  • 41
  • 54
-28

The simple answer to this question is *.* , basically it's completely safe to ignore anything you don't want to add to version control. That being said it really depends on what you're looking to accomplish by using Git. If you want to be able to checkout/import your project elsewhere from the same repository then you'll want to ignore at most /bin/. and /gen/., I wouldn't ignore the folders themselves (i.e. /bin, /gen) just for the sake of maintaining the proper directory structure for your project.

That answers the initial question, but is unrelated to the problem you are having. As far as solving the problem you are experiencing is concerned you would have to post more info, specifically what's listed in the Problems tab. If you can't see the Problems tab anywhere then click on the Window menu, then show view, then choose problems if it's there or click on other and look under General to find it.

Justin Buser
  • 2,813
  • 25
  • 32
  • 3
    This is completely wrong! It will cause git to ignore ALL your files – checklist Sep 10 '13 at 06:20
  • 1
    @checklist Did you not read the question? Or is it that did you not understand my point? He asked "What files/folders can I safely ignore for inclusion with git?", the answer to which IS ANY of them. How do you know he doesn't want to temporarily ignore everything while he works out his build problem? – Justin Buser Mar 16 '14 at 06:52
  • 1
    @JustinBuser that just seems like meaningless, pedantic semantic wrangling. I don't think the artificial context you have concocted has any bearing on the reported question. You appear to be wilfully misinterpreting the OP. – bacar Aug 18 '14 at 14:28