简体   繁体   English

将现有文件提交到现有 Git 存储库,同时保留时间戳

[英]Committing existing files to existing Git repository, while preserving timestamps

The situation is this: I have a bunch of files from ages ago (back when I wasn't using source control of any kind) which I'd love to put to modern-time Git repositories.情况是这样的:我有一堆很久以前的文件(当我没有使用任何类型的源代码控制时),我很想把它们放到现代 Git 存储库中。

I found one tool for this - file-fast-export .我为此找到了一个工具 - file-fast-export It takes existing files and spits out a file that can be fed to git fast-import .它获取现有文件并输出一个可以提供给git fast-import Fine so far.到目前为止还好。

Only problem is that fast-import is a bit picky about input format and file-fast-export isn't a particularly polished program - it assumes files are being imported into a new repository.唯一的问题是快速导入对输入格式有点挑剔,文件快速导出不是一个特别精致的程序——它假设文件被导入到新的存储库中。

So my use case is this: I have a git repository.所以我的用例是这样的:我有一个 git 存储库。 I discovered a previously missing subdirectory.我发现了一个以前丢失的子目录。 File modification times are there.文件修改时间在那里。 I'd need to commit each of those files on top of the current repository history so that the commit timestamps correspond to the modification times.我需要在当前存储库历史记录之上提交每个文件,以便提交时间戳对应于修改时间。 As I understood it, Git doesn't force commits to have chronologically consecutive timestamps, only that commits follow one another.据我了解,Git 不会强制提交具有按时间顺序连续的时间戳,只有提交会相互跟随。 I'm happy if I can just do git log xxxxx.txt and see file history.如果我可以执行git log xxxxx.txt并查看文件历史git log xxxxx.txt我会很高兴。

I'm sure there are tools that can do this.我确信有工具可以做到这一点。 How can I do this?我怎样才能做到这一点?

Only problem is that fast-import is a bit picky about input format唯一的问题是快速导入对输入格式有点挑剔

Actually... With Git 2.28 (Q3 2020), some repositories in the wild have commits that record nonsense committer timezone (eg rails.git );实际上......在 Git 2.28(2020 年第三季度)中,一些野外存储库的提交记录了无意义的提交者时区(例如rails.git ); " git fast-import " learned an option to pass these nonsense timestamps intact to allow recreating existing repositories as-is. git fast-import ”学习了一个选项,可以完整地传递这些无意义的时间戳,以允许按原样重新创建现有存储库。

That could be helpful in your case.这对您的情况可能会有所帮助。

See commit d42a2fb (30 May 2020) by Elijah Newren ( newren ) .请参阅Elijah Newren ( newren ) 的commit d42a2fb (2020 年 5 月 30 日)
(Merged by Junio C Hamano -- gitster -- in commit 5404183 , 02 Jun 2020) (由Junio C gitster合并-- gitster -- in commit 5404183 ,2020 年 6 月 2 日)

fast-import : add new --date-format=raw-permissive format fast-import :添加新的--date-format=raw-permissive格式

Signed-off-by: Elijah Newren签字人: Elijah Newren

There are multiple repositories in the wild with random, invalid timezones.有多个随机、无效时区的存储库。

Most notably is a commit from rails.git with a timezone of "+051800" .最值得注意的是来自rails.git的提交, 时区为 "+051800"

A few searches will find other repos with that same invalid timezone as well.一些搜索也会找到具有相同无效时区的其他存储库。

Further, Peff reports that GitHub relaxed their fsck checks in August 2011 to accept any timezone value , and there have been multiple reports to filter-repo about fast-import crashing while trying to import their existing repositories since they had timezone values such as "-[7349423]" and "-[43455309]" .此外,Peff 报告说GitHub 在 2011 年 8 月放宽了他们的fsck检查以接受任何时区值,并且有多个报告filter-repo存储库关于在尝试导入现有存储库时fast-import崩溃,因为它们具有时区值,例如“- [7349423]”和“-[43455309]”

The existing check on timezone values inside fast-import may prove useful for people who are crafting fast-import input by hand or with a new script.fast-import时区值的现有检查可能对手工或使用新脚本制作快速导入输入的人有用。

For them, the check may help them avoid accidentally recording invalid dates.对他们来说,支票可以帮助他们避免意外记录无效日期。

(Note that this check is rather simplistic and there are still several forms of invalid dates that fast-import does not check for: dates in the future, timezone values with minutes that are not divisible by 15, and timezone values with minutes that are 60 or greater.) (请注意,此检查相当简单,但仍有几种形式的无效日期无法进行快速导入检查:将来的日期、不能被 15 整除的分钟的时区值以及分钟为 60 的时区值或更高。)
While this simple check may have some value for those users, other users or tools will want to import existing repositories as-is.虽然这个简单的检查可能对这些用户有一些价值,但其他用户或工具将希望按原样导入现有存储库。
Provide a --date-format=raw-permissive format that will not error out on these otherwise invalid timezones so that such existing repositories can be imported.提供一个--date-format=raw-permissive格式,该格式不会在这些否则无效的时区上出错,以便可以导入此类现有存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM