Wednesday, 14 October 2015

Do not ignore your .gitignore

A quick way to find out what is ignored?

$ git check-ignore -v  *

The story:

I had a source (src) directory called src/main/orchestra/weekly/build i was working with.
Pushed my changes from work and pulled it from home, i could not see all the work i had done in the src/main/orchestrator/weekly/build  directory because i had this entry in my .gitignore

$ vim .gitignore

 **/.gradle
 **/build/
 .idea/
 **/.iml
 **/*.pyc

The second entry was there to ignore the ./build directory which has all the jars, classes and the app packaged together. This directory is normally ignored in Java projects. This can be very confusing.


All the tests had passed, because the files still exist on disk, but will not be pushed. I did ignore the build failure on the CI (Continous Integration) box because there were some configuration changes needed and i did not have access to the Build plan and the admin was away sick.

You see this wasn't entirely my mistake ;)

Moral of the story is to run:
$ git check-ignore -v  *
.gitignore:2:build/ build   ---> Result of running the command

To check what is actually ignored by git. If i had run it then i would seen that:

src/main/orchestrator/weekly/build was ignored because of the rule  - **/build/ in my .gitignore.

Solution:
Explicitly ignore the root level build directory in your .gitignore with the entry:

build/

Hope that helps someone somewhere.