将大型 Git 存储库拆分为许多较小的存储库 [英] Split large Git repository into many smaller ones

查看:24
本文介绍了将大型 Git 存储库拆分为许多较小的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在成功将 SVN 存储库转换为 Git 后,我​​现在有一个非常大的 Git 存储库,我想将其分解为多个较小的存储库并维护历史记录.

After successfully converting an SVN repository to Git, I now have a very large Git repository that I want to break down into multiple smaller repositories and maintain history.

那么,有人可以帮助分解看起来像这样的存储库吗:

So, can someone help with breaking up a repo that might look like this:

MyHugeRepo/
   .git/
   DIR_A/
   DIR_B/
   DIR_1/
   DIR_2/

进入两个看起来像这样的存储库:

Into two repositories that look like this:

MyABRepo/
   .git
   DIR_A/
   DIR_B/

My12Repo/
   .git
   DIR_1/
   DIR_2/

我已尝试按照上一个问题中的说明进行操作,但在尝试将多个目录放入单独的存储库时,它并不真正适合 (将子目录分离(移动)到单独的 Git 存储库中).

I've tried following directions in this previous question but it doesn't really fit when trying to put multiple directories into a separate repo (Detach (move) subdirectory into separate Git repository).

推荐答案

这将设置 MyABRepo;你当然可以类似地做 My12Repo.

This will setup MyABRepo; you can do My12Repo similarly of course.

git clone MyHugeRepo/ MyABRepo.tmp/
cd MyABRepo.tmp
git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD 

对 .git/refs/original/refs/heads/master 的引用仍然存在.您可以删除它:

A reference to .git/refs/original/refs/heads/master remains. You can remove that up with:

cd ..
git clone MyABRepo.tmp MyABRepo

如果一切顺利,您可以删除 MyABRepo.tmp.

If all went well you can then remove MyABRepo.tmp.

如果由于某种原因你得到关于 .git-rewrite 的错误,你可以试试这个:

If for some reason you get an error regarding .git-rewrite, you can try this:

git clone MyHugeRepo/ MyABRepo.tmp/
cd MyABRepo.tmp
git filter-branch -d /tmp/git-rewrite.tmp --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD 
cd ..
git clone MyABRepo.tmp MyABRepo

这将创建和使用/tmp/git-rewrite.tmp 作为临时目录,而不是 .git-rewrite.当然,你可以替换任何你想要的路径而不是 /tmp/git-rewrite.tmp,只要你有写权限,并且目录不存在.

This will create and use /tmp/git-rewrite.tmp as a temporary directory, instead of .git-rewrite. Naturally, you can substitute any path you wish instead of /tmp/git-rewrite.tmp, so long as you have write permission, and the directory does not already exist.

这篇关于将大型 Git 存储库拆分为许多较小的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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