I'm trying to git archive a branch using gzip with the highest level compression (9) but it seems to not compress at that level. Here is my command:
git -C /home/user/example.com/ archive --format tar -o /home/user/site_backups/develop-`date +%Y-%m-%dT%H%M`.tar develop | gzip -9
It creates the tar file but the size is over 100MB compared to a zip that was compressed at 86MB using this command:
git -C /home/user/example.com/ archive --format zip -o /home/user/site_backups/develop-`date +%Y-%m-%dT%H%M`.zip develop
Can the output file be compressed more? What am I doing wrong?
Nowadays (4 years later), the command would be:
With Git 2.30 (Q1 2021), "
git archive"(man) now allows compression level higher than "-9" when generating tar.gz output.See commit cde8ea9 (09 Nov 2020) by René Scharfe (
rscharfe).(Merged by Junio C Hamano --
gitster-- in commit ede4d63, 18 Nov 2020)Note that, with Git 2.38 (Q3 2022), "
git archive"(man) now (optionally and then by default) avoids spawning an external "gzip" process when creating ".tar.gz" (and ".tgz") archives.See commit 4f4be00, commit 23fcf8b, commit 76d7602, commit dfce118, commit 96b9e51, commit 650134a (15 Jun 2022) by René Scharfe (
rscharfe).(Merged by Junio C Hamano --
gitster-- in commit b5a2d6c, 11 Jul 2022)'./git -C ../linux archive --format=tar HEAD # {rev}'
Only an internal sequential implementation can offer this eco mode, and it allows avoiding the
gzip(1)requirement.And:
git archivenow includes in its man page:So a
git archiveusing an external gzip would be:While the new default one would use the internal zlib:
In both cases, the compression level options mentioned above still apply.