【问题标题】:git filter-branch remove all submodules from my repogit filter-branch 从我的仓库中删除所有子模块
【发布时间】:2014-06-06 02:10:38
【问题描述】:

您好,我已成功重写历史记录,并使用git filter-branch -f --prune-empty --tree-filter 'rm -rf <all unwanted dirs>' 获取了我想提取的 5 个文件夹并保留了所有 git 历史记录。

唯一剩下的问题是子模块,我还有提交做

Subproject commit <hash>

我想从我的 git 历史记录中完全删除所有这些子模块提交,我该如何完成?

【问题讨论】:

  • git rm 它们与 filter-branch 的 --index-filter 以及 git rm .gitmodules 一起使用,因此 git submodule 命令不会认为它们丢失了。
  • 已经尝试过了,但最后我得到了灰色的幽灵子模块文件夹
  • 你还需要git submodule deinit他们。
  • @jthill 尝试了 git submodule deinit .,但在运行 --tree-filter 脚本时出现 git 错误

标签: git github revision-history git-rewrite-history


【解决方案1】:

我已经做到了

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

假设我所有的子模块都位于lib 目录中

【讨论】:

  • 如果我的子模块在根目录下怎么办?
【解决方案2】:

其他解决方案对我不起作用。继how to remove submodules 上投票最多的答案之后,我使用了以下命令,该命令更灵活,因为您可以在多个文件夹中指定子模块:

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

实际上,我们正在检查每个提交的子模块文件夹列表。如果子模块文件夹存在,我们完全删除子模块。从技术上讲,仅此一项就足够了,我们还想摆脱.gitmodules 文件。如果您只想删除特定的子模块,则该行可能需要一些额外的工作。

【讨论】:

    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2016-12-15
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    相关资源
    最近更新 更多