Git:将文件移动到现有子模块中 [英] Git: Moving files into an existing submodule
问题描述
如何将主仓库中的文件和文件夹移动到现有子模块中?我可以以某种方式保存历史吗?
How do I move files and folders in my master repo into an existing submodule? Can I preserve history somehow?
推荐答案
假设存储库中只有一个分支:接收子模块存储库,将主存储库添加为第二个远程存储库,获取历史记录并删除除选择的文件.将结果合并到主存储库分支.
Assuming you have only a single branch in you repos: take your submodule repo, add your master repo as a second remote, fetch the history and remove everything but the chosen files. merge the result to you master repository branch.
此处删除"可能意味着两件事.一个简单的git rm
都将创建一个干净的HEAD,但是删除的文件将保留在历史记录中.或git filter-branch
能够创建仅包含所选文件的新历史记录.
Here "remove" could mean two things. Either a simple git rm
which will create a clean HEAD but the deleted files will remain in history. Or a git filter-branch
which is able to create a new history consisting only of the chosen files.
在主存储库中,您基本上具有相同的选择.使用git rm
删除HEAD中已移动的文件,或者使用git filter-branch
从整个历史记录中删除它们.
At your master repository you have basically the same options. Either use git rm
to delete the moved files in HEAD or use git filter-branch
to remove them from the whole history.
这篇关于Git:将文件移动到现有子模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!