Git:将文件移动到现有子模块中 [英] Git: Moving files into an existing submodule

查看:96
本文介绍了Git:将文件移动到现有子模块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将主仓库中的文件和文件夹移动到现有子模块中?我可以以某种方式保存历史吗?

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屋!

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