git - 当项目包含其他子模块时 git filter-branch 不起作用
问题描述
假设我有以下项目结构:
.git
--APP
-----F
--LIBS
------A
-------.git
------B
-------.git
------C
-------.git
------D
-------.git
F
是APP文件夹下的子文件夹。
A, B, C
并且D
是位于 LIBS 文件夹下的四个子模块。
我想要做的是将F
文件夹提取到不同的存储库(目前它只是一个简单的子文件夹)。
到目前为止,我已经完成了以下工作:
for remote in `git branch -r | grep -v /HEAD`; do git checkout --track $remote; done
之后,我跑了:
git filter-branch --prune-empty --tag-name-filter cat --subdirectory-filter APP/F/ -- --all
结果是:
.git
--F
--LIBS
------A
-------.git
------B
-------.git
------C
-------.git
------D
-------.git
似乎层次结构中的子模块仍然改写了历史。
但是,我想要的结果是只保留 F 目录,没有其他子模块..:
--F
---.git
解决方案
filter-branch
不是使用子模块的正确工具。您想要的是删除相应的子模块(使用 rm),然后使用 filter-branch 移动层次结构根,如下所示:
rm -r LIBS && git add --all && git commit -m "Dropped submodules"
git filter-branch --prune-empty --tag-name-filter cat --subdirectory-filter APP/F/
推荐阅读
- html - 使用 ASP.NET WEB SERVICE(.asmx) 的 HTML 表数据绑定
- javascript - 如何在动态值旁边显示温度和百分比符号
- firebase - Flutter Firebase 集成构建失败,出现 :app:processDebugManifest
- authentication - 创建无需身份验证即可访问的 Mashery API 定义
- python - 如何按照kedro管道中声明的顺序运行节点?
- python - 使用循环、元组、列表、字典等的销售计算器
- c# - 使用保存在变量中的类型调用泛型函数
- flask - 在哪里放置 setup.py 文件以使 Flask 项目可安装?
- php - SmartyException 0():Prestashop 缺少“$template”参数
- python - AttributeError:“系列”对象没有属性“上”