如何将github repo一分为二?

c6ubokkw  于 5个月前  发布在  Git
关注(0)|答案(1)|浏览(62)

我的github repo有两个文件夹:客户端/服务器。我需要从这些文件夹中创建单独的仓库,但这样每个仓库的提交历史不会丢失。之后,必须删除主仓库。我在互联网上遇到了filter-repo实用程序,但我没有真正弄清楚它是如何工作的。你能帮我吗?
主存储器:

.git
  client
  server

字符串
预期结果:

client:
    .git

  server:
    .git


thx!

gzjq41n4

gzjq41n41#

subtree split

TL;DR;

subtree split会将你的内容“拆分”到分支中

长回答

  • 将主分支(整个内容)按“文件夹”拆分为分支。
  • 从新分支(add、commit和push)创建子模块到新的git repo

怎么做的?
git subtree split <path> -b <branch>,然后为每个子模块添加remote,并将分支推送到remote。

# split the "main repo" into branches and preserve full history
git subtree split -P client -b <client>
git subtree split -P server -b <server>

# For each branch that you extract client/server
# create a git repo (which will be used for submodules)

# Add the content to the git server
# add remote for client
git remote add submodule1 <client_url>

# push the submodule
git push submodule1 <branch>

字符串

  • 一旦你设置好了所有的子模块,就把它们添加到“主”存储库中
# Add the submodules 
git submodule add <url>


添加完所有子模块后,提交.gitmodules文件

相关问题