gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:04:56 24 4
gpt4 key购买 nike

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

大家好

我有一些关于 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 内部格式”将日期设置为 1970-01-01,详情请参阅 git-commit-tree 的联机帮助页.

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

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 --version 给出 git version 1.7.1

最佳答案

在 git 日期解析器代码中找到:

/*
* 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 日期,并且该字符串不会解析为任何其他日期格式,因此 GIT_AUTHOR_DATE 被视为无效并被完全忽略(显然,静默) .

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

关于git 忽略 $GIT_AUTHOR_DATE——这是一个错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5093533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com