Friday, October 17, 2008

Adding an empty folder to a Git repository

You can't actually add an empty folder to a Git repository - it handles files not folders. In my case though, I like to have the repo holding an empty copy of my "dist" folder so that I can grab the repo and then do a build without having to create the "dist" folder separately.

My solution is to created the folder and add a ".gitignore" file in there. In order to ignore everything in that folder (apart from itself), the .gitignore file has the following contents:

# Ignore everything in here apart from the .gitignore file
*
!.gitignore


The only other thing I need to do is ensure that my ant build script does not delete the .gitignore file everytime I do a build and clean the "dist" folder. So I add this "exclude" code to my build.xml script:


<delete>
<fileset dir="${dist.dir}">
<exclude name=".gitignore" />
<include name="**/*.*"/>
</fileset>
</delete>


In hindsight, I probably should have gotten the build script to create the "dist" folder. Nevermind, but it was fun trying to find a solution!

1 comment:

Unknown said...

I faced this problem when trying to use git as a backup tool with support for deduplication and compression.

My solution was to create my own system. It's available on http://github.com/meingbg/store

But again, that's for keeping files, not code.