Creating a git repository for testing.~ $ mkdir somefolder~ $ cd somefolder/~/somefolder $ git initInitialized empty Git repository in /home/user/somefolder/.git/  ~/somefolder $ echo test > xyz  ~/somefolder $ mkdir somefolder2  ~/somefolder $ echo test2 > ./somefolder2/zzz  ~/somefolder $ git add *  ~/somefolder $ git commit -a -m .[master (root-commit) 591fda9] . 2 files changed, 2 insertions(+) create mode 100644 somefolder2/zzz create mode 100644 xyzWhen turning the whole repository into a tar.gz, it results in a determinstic file. Example.  ~/somefolder $ git archive \>    --format=tar \>    --prefix=test/ \>    HEAD \>    | gzip -n > test.orig.tar.gz  ~/somefolder $ sha512sum test.orig.tar.gze34244aa7c02ba17a1d19c819d3a60c895b90c1898a0e1c6dfa9bd33c892757e08ec3b7205d734ffef82a93fb2726496fa16e7f6881c56986424ac4b10fc0045  test.orig.tar.gzAgain.  ~/somefolder $ git archive \>    --format=tar \>    --prefix=test/ \>    HEAD \>    | gzip -n > test.orig.tar.gz  ~/somefolder $ sha512sum test.orig.tar.gze34244aa7c02ba17a1d19c819d3a60c895b90c1898a0e1c6dfa9bd33c892757e08ec3b7205d734ffef82a93fb2726496fa16e7f6881c56986424ac4b10fc0045  test.orig.tar.gzWorks.But when changing a minor detail, when only compressing a sub folder, it does not end up with a deterministic file. Example.  ~/somefolder $ git archive \>    --format=tar \>    --prefix=test/ \>    HEAD:somefolder2 \>    | gzip -n > test2.orig.tar.gz  ~/somefolder $ sha512sum test2.orig.tar.gzb523e9e48dc860ae1a4d25872705aa9ba449b78b32a7b5aa9bf0ad3d7e1be282c697285499394b6db4fe1d4f48ba6922d6b809ea07b279cb685fb8580b6b5800  test2.orig.tar.gzAgain.  ~/somefolder $ git archive \>    --format=tar \>    --prefix=test/ \>    HEAD:somefolder2 \>    | gzip -n > test2.orig.tar.gz  ~/somefolder $ sha512sum test2.orig.tar.gz06ebd4efca0576f5df50b0177d54971a0ffb6d10760e60b0a2b7585e9297eef56b161f50d19190cd3f590126a910c0201616bf082fe1d69a3788055c9ae8a1e4  test2.orig.tar.gzNo deterministic tar.gz this time for some reason.How to create a deterministic tar.gz using git-archive when just wanting to compress a single folder?
How to create a deterministic tar.gz using git-archive?
command line;tar;git;gzip
When you do a simple export with HEAD, an internal timestamp is initialized based on the commit's timestamp. When you use more advanced filtering options, the timestamp is set to the current time. To change the behavior, you need to fork/patch git and change the second scenario, eg proof of concept:diff --git a/archive.c b/archive.cindex 94a9981..0ab2264 100644--- a/archive.c+++ b/archive.c@@ -368,7 +368,7 @@ static void parse_treeish_arg(const char **argv,                archive_time = commit->date;        } else {                commit_sha1 = NULL;-               archive_time = time(NULL);+               archive_time = 0;        }        tree = parse_tree_indirect(sha1);