Sunday, 29 December 2013

How get rid off annoying bin gen folders from git repository - intellij / android studio

There two ways to get rid off it:
Case 1: you have just created new project and didn't commit first changes:
It's better because you have clean plate and you can define what should be ignored.

I'm using this text which is saved in .gitignore file placed in main project, but if you are using another libraries you can put .gitignore also there.

 ### Android ###  
 # 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/  
 project.properties  
 .settings/  
 out/  

I know there are sometimes problems with gitignore files, please try save file by notepad++ and it should be good solution for windows users.


Case 2:
You have commited some changes and forgot to put .gitignore

Well this is the hard part because even you commited own .gitignore file - not all filles will be ignored anyway... You might think it doesn't work but this is how it works: all filles which were commited goes to "checking file list" and if you change them, they will be also raported as changed..

What to do then? In few steps:

for example with bin folder (it was commited and you forgot to ignore it)
0. Put own .gitignore file by placing it in proper main project folder and commit changes
1. Remove or move out of project bin folder (just make sure bin is gone while doing this operation, intellij tends to autogenerate bin and gen folders, so make sure intellij is closed)
2. if you write now git status inconsole, you will see bin folder was deleted
3. Commit changes - bin will be removed so there will be no checking this folder/files in future
4. Put bin folder back or let intellij generate new bin folder
5. Check if git found bin folder by writting in console git status, if there is no any information about bin folder, it means it is now ignored by git:)