回顾性地将git文件夹转换为子模块? [英] Convert a git folder to a submodule retrospectively?
问题描述
有没有办法将其中一个一个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屋!