git archive provides an easy way of producing a tarball (or a zip file) directly from a project's git branch.
For example, this is what we use to build the Mahara tarballs:
git archive --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | bzip2 -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.bz2
If you do this however, you end up with the entire contents of the git branch, including potentially undesirable files like .gitignore
.
There is an easy, though not very well-documented, way of specifying files to exclude from such exports: gitattributes.
This is what the Mahara .gitattributes
file looks like:
/test export-ignore .gitattributes export-ignore .gitignore export-ignore
With this file in the root directory of our repository, tarballs we generate using git archive
no longer contain the selenium tests or the git config files.
If you start playing with this feature however, make sure you commit the .gitattributes
file to your repository before running git archive
. Otherwise the settings will not be picked up by git archive
.