Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignores $GIT_AUTHOR_DATE -- is this a bug?

EDIT: Summary: Git does not allow dates before 1973/03/03 09:46:40 (epoch+100000000s) given in its "internal date format" (seconds since the epoch). This is to allow "20110224" as short form of "2011-02-24". -- This Is no bug: Not really, but it is not documented as well. -- Workaround: Do not rely on the git internal date when you cannot. -- Thanks to: hobbs

Hi all,

I have some issues with git filter-branch that I have tracked down to 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 the env GIT_AUTHOR_DATE="0 +0000" sets the date using the "Git internal format" -- see git-commit-tree's manpage for details -- to 1970-01-01.

But the output of this script (the raw commit) is

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 ignoring $GIT_AUTHOR_DATE? If that is of significance, my git --version gives git version 1.7.1.

like image 789
Prestel Nué Avatar asked Feb 23 '11 16:02

Prestel Nué


1 Answers

Found in the git date parser 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 that code explicitly rejects small numbers as possible unix-dates, and the string doesn't parse as any other date format, GIT_AUTHOR_DATE is treated as invalid and ignored entirely (and apparently, silently).

Your method should work fine though as long as you stick to synthesizing commits that took place after 1973. Otherwise, use one of the other date formats :)

like image 77
hobbs Avatar answered Sep 20 '22 00:09

hobbs