如何在不破坏文件历史记录的情况下组合多个 Git 存储库? [英] How do I combine several Git repositories without breaking file history?

查看:34
本文介绍了如何在不破坏文件历史记录的情况下组合多个 Git 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试从 TFS 迁移.使用 git-tfs 工具,我们能够迁移现有存储库的部分内容,但它在某些麻烦的签入时崩溃.我们已经能够制作一组拼凑的 Git 存储库,涵盖大部分原始 TFS 提交.

We are trying to migrate away from TFS. Using the git-tfs tool, we were able to migrate parts of the existing repo, but it crashes at certain troublesome checkins. We have been able to make a patchwork set of Git repos that cover most of the original TFS commits.

目前拥有:

  • 从 2009 年到 2011 年有变化的 Git 存储库
  • 从 2011 年到 2016 年有变化的 Git 存储库
  • Git 存储库从 2016 年到现在的变化

期望:

  • 涵盖 2009 年至今的大型 Git 存储库
  • 任何一直存在的文件都会有一个文件历史

有什么方法可以让我们将这些重新拼接成一个 Git 存储库?我们不在乎保留 SHA(无论如何它们都是新的),但我们不能破坏文件历史记录.

Is there any way for us to stitch these back together into a single Git repo? We don't care about retaining SHAs (they're all new anyway), but we can't break file history.

推荐答案

edit: 最新版本的 git 现在扩展了 git replace 命令,使用 git replace 可以更轻松地完成此操作 --移植<提交><parent>(参见 https://git-scm.com/docs/git-replace#Documentation/git-replace.txt---graftltcommitgtltparentgt82308203 )

edit: recent versions of git has now extended the git replace command to do it more easily with git replace --graft <commit> <parent> (See https://git-scm.com/docs/git-replace#Documentation/git-replace.txt---graftltcommitgtltparentgt82308203 )

使用 git 的嫁接"功能有一种简单的方法可以做到这一点.这是一个与@torek 提到的 git replace 目标相同的功能,但在您的情况下更容易使用.

There is an easy way to do that using the 'graft' feature of git. it's a feature with the same goal than git replace that @torek mentioned but that is easier to use in your case.

首先,导入同一存储库中的所有历史记录.在最新的存储库中,为另外 2 个执行:

First, import all the histories in the same repository. In the most recent repository, do for the 2 others:

  1. git remote add c:/path/toward/other/repository
  2. git fetch

然后按照帮助创建git移植文件.git/info/grafts:https://git.wiki.kernel.org/index.php/GraftPoint(您的文件中应该有 2 行)

Then create the git graft file .git/info/grafts following the help: https://git.wiki.kernel.org/index.php/GraftPoint (you should have 2 lines in your file)

如果您使用 git log 或任何 Git GUI,您现在应该可以看到您想要的历史记录.

If you use git log or any Git GUI, you now should see the history like you want it.

如果您满意,请重写历史记录以使其具有确定性:

If you are satisfied, then rewrite the history to make it definitive with:

git filter-branch

您现在可以将历史记录推送到中央存储库或共享它.

You could now push your history to a central repository or share it.

Ps:关于该主题的另一个文档,但融合移植并替换 git 功能:https://legacy-developer.atlassian.com/blog/2015/08/grafting-earlier-history-with-git/

Ps: another doc on the subject but melting grafts and replace git features : https://legacy-developer.atlassian.com/blog/2015/08/grafting-earlier-history-with-git/

这篇关于如何在不破坏文件历史记录的情况下组合多个 Git 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆