简体   繁体   English

git filter-branch 从我的仓库中删除所有子模块

[英]git filter-branch remove all submodules from my repo

Hello I have successfully rewrote history and got the 5 folders I wanted to extract using git filter-branch -f --prune-empty --tree-filter 'rm -rf <all unwanted dirs>' and kept all git history.您好,我已成功重写历史记录并使用git filter-branch -f --prune-empty --tree-filter 'rm -rf <all unwanted dirs>'获得了我想提取的 5 个文件夹,并保留了所有 git 历史记录。

The only remaining issue are submodules, I sill have commits doing唯一剩下的问题是子模块,我还有提交

Subproject commit <hash>

and I want to completely remove ALL of those submodule commits from my git history, how can I accomplish this?我想从我的 git 历史记录中完全删除所有这些子模块提交,我该如何完成?

I have done it with我已经做到了

git filter-branch -f --prune-empty --tree-filter '
    git submodule deinit -f .
    git rm -rf lib && rm -rf lib
    find . -name .gitmodules -delete' HEAD

Assuming that all of my submodules were located in lib directory假设我所有的子模块都位于lib目录中

The other solution did not work for me.另一个解决方案对我不起作用。 Following the top voted answer on how to remove submodules , I used the following command, which is more flexible, as you can specify submodules in multiple folders:按照关于如何删除子模块的最高投票答案,我使用了以下命令,它更灵活,因为您可以在多个文件夹中指定子模块:

git filter-branch -f --prune-empty --tree-filter '
    for SUBMODULE_DIR in submodule-dir-1 lib/submodule-dir-2 lib/submodule-dir-3
    do
        if [ -d $SUBMODULE_DIR ]; then
            git submodule deinit -f $SUBMODULE_DIR
            git rm -rf .git/modules/$SUBMODULE_DIR
            git rm -f $SUBMODULE_DIR
        fi
    done
    git rm -f --ignore-unmatch .gitmodules' HEAD

Effectively we are checking the list of submodule folders for each commit.实际上,我们正在检查每个提交的子模块文件夹列表。 If the submodule folder exists, we completely remove the submodule.如果子模块文件夹存在,我们完全删除子模块。 Technically that alone is sufficient, be we also want to get rid of the .gitmodules file.从技术上讲,仅此一项就足够了,因为我们还想摆脱.gitmodules文件。 If you only want to delete specific submodules, that line might need some additional work.如果您只想删除特定的子模块,该行可能需要一些额外的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM