gpt4 book ai didi

git - 我如何使用 git-filter-repo 来修复错误的日期

转载 作者:行者123 更新时间:2023-12-05 05:49:41 25 4
gpt4 key购买 nike

我有一个 git 存储库,它是多年前通过 CVS 从 RCS 转换而来的。当我试图将它推送到 GitHub 时,它被拒绝了,因为前两次提交的日期不正确:

$ git fsck
Checking object directories: 100% (256/256), done.
error in commit 38f10a1a015625149ea06f2f633e9ba446912b27: badDateOverflow: invalid author/committer line - date causes integer overflow
error in commit 0436a5befd4fee58693c2293e72be53b84705539: badDateOverflow: invalid author/committer line - date causes integer overflow

当我查看这些提交时,很明显日期是错误的(它们是负数):

$ git cat-file -p 
tree 75e9d9b58efcc2b706e38967cff75935e656fdf1
parent 0436a5befd4fee58693c2293e72be53b84705539
author John Tang Boyland <boyland@uwm.edu> -59025288066 +0000
committer John Tang Boyland <boyland@uwm.edu> -59025288066 +0000

Updated for CS654 Spring 1999.

这似乎是 git-filter-repo 应该能够处理的事情。我看到了用于修复电子邮件和名称以及提交消息的标志,但没有关于日期的标志。我尝试了一次运行,我只是修剪了无法访问的提交,并且它留下了错误的日期。然后我尝试使用 git fast-export 并使用正确的 unix 时间戳编辑负数。当我使用 git fast-import 进入一个空的存储库时,我得到了大量的统计信息,但空的存储库仍然是空的,这可能是因为提交结构被破坏了。我猜解决这个问题的唯一方法是使用 git-filter-repo 的提交回调,但我不确定如何修复日期。

我试过了

$ git-filter-repo --commit-callback '
if (commit.committer_date == -59025288066) :
commit.committer_date = 932873934
'

它运行良好,但对坏日期没有影响。我尝试做同样的事情,但将日期用双引号引起来(以防它们被读取为字符串),同样无济于事。

我看到一个关于同一主题的现有问题,但答案没有说明如何使用 git-filter-repo 来修复日期:How can I fix "bad date" issues in a git repository?

最佳答案

好的,经过一些实验,我发现了如何使用钩子(Hook)。双引号日期戳是不够的,它还必须有 +0000 部分。甚至那还不够。我不得不“b”引用字符串。解决方案是使用一个钩子(Hook)运行 git-filter-repo

git-filter-repo --commit-callback '
if (commit.committer_date == b"-59025288066 +0000") :
commit.committer_date = b"932873934 +0000"
'

当然,然后我必须对 author_date 和其他提交做同样的事情。

关于git - 我如何使用 git-filter-repo 来修复错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70635488/

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