Git ignores $ GIT_AUTHOR_DATE - is that a bug?

EDIT : Summary: Git does not allow dates until 1973/03/03 09:46:40 (epoch + 100000000 s) specified in its "internal date format" (seconds from epoch). This should allow “20110224” as a short form of “2011-02-24”. - This is not a mistake: Not really, but it is not documented. - Workaround: Do not rely on Git's internal date when you cannot. - Thanks: hobbs

Hello to all,

I have some problems with the Git filter branch that I tracked to the Git commit-tree. Consider this script:

#!/bin/bash # please run these commands in an empty directory # (should not destroy an existing repo, though. I think it would only # a few dangling objects) set -e -o pipefail git init tree=$(git write-tree) commit=$(echo "my first commit -- the tree is empty" | env GIT_AUTHOR_DATE="0 +0000" git commit-tree $tree) echo "This is commit $commit:" git cat-file commit $commit 

Note that env GIT_AUTHOR_DATE="0 +0000" sets the date using the internal Git format - see the git-commit-tree manpage for details - until 1970-01-01.

But the output of this script (raw commit)

 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 author Jane Doe <jane> 1298477214 +0100 committer Jane Doe <jane> 1298477214 +0100 my first commit -- the tree is empty 

Now why is Git ignored by $ GIT_AUTHOR_DATE? If that matters, my git --version gives git version 1.7.1 .

+6
git git-filter-branch
source share
1 answer

Found in git date analyzer code:

 /* * Seconds since 1970? We trigger on that for any numbers with * more than 8 digits. This is because we don't want to rule out * numbers like 20070606 as a YYYYMMDD date. */ if (num >= 100000000 && nodate(tm)) { 

Since this code explicitly rejects small numbers as possible unix dates, and the string is not parsed like any other date format, GIT_AUTHOR_DATE is considered invalid and completely ignored (and apparently silently).

Your method should work fine if you stick to the synthetic commits that occurred after 1973. Otherwise, use one of the other date formats :)

+19
source share

All Articles