假设我有以下项目结构:
.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/
关于当项目包含其他子模块时,git filter-branch 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631677/