git忽略$ GIT_AUTHOR_DATE - 这是一个错误吗?

时间:2011-02-23 16:12:34

标签: git git-filter-branch

  

编辑摘要:Git不允许在“内部日期格式”中给出1973/03/03 09:46:40(epoch + 100000000s)之前的日期(自纪元以来的秒数)。这是允许“20110224”作为“2011-02-24”的缩写形式。 - 这不是错误:不是真的,但也没有记录。 - 解决方法:当你不能时,不要依赖git内部日期。 - 感谢:hobbs

大家好,

我遇到了git filter-branch的一些问题,我已经跟踪到了git commit-tree。考虑一下这个脚本:

#!/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

请注意,env GIT_AUTHOR_DATE="0 +0000"使用“Git内部格式”设置日期 - 有关详细信息,请参阅git-commit-tree的联机帮助页 - 至1970-01-01。

但是这个脚本的输出(原始提交)是

tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
author Jane Doe <jane> 1298477214 +0100
committer Jane Doe <jane> 1298477214 +0100

my first commit -- the tree is empty

现在为什么git会忽略$ GIT_AUTHOR_DATE?如果这有意义,我的git --versiongit version 1.7.1

1 个答案:

答案 0 :(得分:19)

在git date解析器代码中找到:

/*
 * 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)) {

由于该代码明确拒绝小数字作为可能的unix-date,并且该字符串不像任何其他日期格式一样解析,GIT_AUTHOR_DATE被视为无效并被完全忽略(显然,默默地)。

你的方法应该可以正常工作,只要你坚持合成1973年以后发生的提交。否则,使用其他日期格式之一:)