如何将一个目录从git存储库移动到新的存储库,同时保留历史记录? [英] How can I move a single directory from a git repository to a new repository whilst maintaining the history?

查看:78
本文介绍了如何将一个目录从git存储库移动到新的存储库,同时保留历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个git仓库,其中包含多个项目在不同的目录中。我想将存储库拆分为新的单独存储库,每个项目一个,然后让主存储库包含作为子模块的项目。如果可能的话,我会尽可能保持个别项目的修订历史记录。



我可以为每个项目克隆存储库并删除所有其他项目但是有没有更好的方法来避免每个新项目存储库中都有克隆的历史记录?

您可以使用 git filter-branch 重写一个项目的历史。从文档:


如果foodir /是它的项目根目录,将存储库重写为

并放弃所有其他历史记录:

  git filter-branch --subdirectory-filter foodir  -  --all 


为您的repo制作多份副本,为您要拆分的每个子目录执行此操作,你应该找到你正在寻找的东西。


I have inherited a git repository containing multiple projects in separate directories. I'd like to split the repository into new individual repositories, one for each project and then have the master repository contain the projects as submodules. I'd like to do all this whilst maintaining the revision history of the individual projects if possible.

I could clone the repository for each project and remove all the other projects each time, but it there a better way to avoid having the cloned history in each new project repository?

解决方案

You can use git filter-branch to rewrite the history of a project. From the documentation:

To rewrite the repository to look as if foodir/ had been its project root, and discard all other history:

git filter-branch --subdirectory-filter foodir -- --all

Make several copies of your repo, do that for each subdirectory you want to split out, and you should wind up with what you're looking for.

这篇关于如何将一个目录从git存储库移动到新的存储库,同时保留历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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