![](/img/trans.png)
[英]How to use git-filter-repo to merge one repo as subdirectory into another
[英]How do I use git-filter-repo to fix a bad date
我有一个多年前通过 CVS 从 RCS 转换的 git 存储库。 当我试图将它推送到 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
修复日期: 如何修复 git 存储库中的“错误日期”问题?
好的,经过一些实验,我发现了如何使用钩子。 双引号日期戳是不够的,它也必须有+0000
部分。 甚至这还不够。 我不得不“b”引用字符串。 解决方案是使用钩子运行git-filter-repo
,例如
git-filter-repo --commit-callback '
if (commit.committer_date == b"-59025288066 +0000") :
commit.committer_date = b"932873934 +0000"
'
当然,然后我必须对author_date
和另一个提交做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.