回顾性地将git文件夹转换为子模块? [英] Convert a git folder to a submodule retrospectively?

查看:332
本文介绍了回顾性地将git文件夹转换为子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常情况下,你正在编写某种项目,过了一段时间,很明显项目的某些组件实际上可以作为独立组件(可能是一个库)有用。如果你从早期就有了这个想法,那么很可能大部分代码都在它自己的文件夹中。



有没有办法将其中一个一个git项目的子目录到子模块中?理想情况下,会发生这样的情况,即该目录中的所有代码都将从父项目中删除,并且将子模块项目添加到它的位置,并添加所有相应的历史记录,并且所有父项目提交指向正确的子模块提交。

解决方案

要将子目录分离到其自己的存储库中,请使用 filter-branch 在原始存储库的克隆上:

  git clone< your_project> < your_submodule> 
cd< your_submodule>
git filter-branch --subdirectory-filter'path / to / your / submodule'--prune-empty - --all

然后,只需删除原始目录并将子模块添加到父项目即可。


Quite often it is the case that you're writing a project of some kind, and after a while it becomes clear that some component of the project is actually useful as a standalone component (a library, perhaps). If you've had that idea from early on, then there's a fair chance that most of that code is in it's own folder.

Is there a way to convert one of a git project's sub directories into a submodule? Ideally this would happen such that all of the code in that directory is removed from the parent project , and the submodule project is added in it's place, with all the appropriate history, and such that all the parent project commits point to the correct submodule commits.

解决方案

To isolate a subdirectory into its own repository, use filter-branch on a clone of the original repository:

git clone <your_project> <your_submodule>
cd <your_submodule>
git filter-branch --subdirectory-filter 'path/to/your/submodule' --prune-empty -- --all

It's then nothing more than deleting your original directory and adding the submodule to your parent project.

这篇关于回顾性地将git文件夹转换为子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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