Pre*_*Nué 6 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
Run Code Online (Sandbox Code Playgroud)
请注意,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
Run Code Online (Sandbox Code Playgroud)
现在为什么git忽略$ GIT_AUTHOR_DATE?如果这很重要,我git --version会给出git version 1.7.1.
hob*_*bbs 20
在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)) {
Run Code Online (Sandbox Code Playgroud)
由于该代码明确拒绝小数字作为可能的unix-date,并且字符串不像任何其他日期格式一样解析,GIT_AUTHOR_DATE因此被视为无效并完全被忽略(显然,默默地).
只要您坚持1973年之后发生的综合提交,您的方法应该可以正常工作.否则,使用其他日期格式之一:)