git - 如何从没有子模块的分支 check out 带有子模块的分支

标签 git git-submodules

我的本地机器上有三个分支:

  • 大师
  • 带子模块的功能分支
  • 没有子模块的功能分支

  • 没有子模块的分支曾经有一个子模块,我按照 this SO post 中的说明删除了子模块.我不想从 master 中删除子模块和 feature-branch-with-submodule .

    但是,现在我已经完成了 feature-branch-without-submodule ,我想切换到feature-branch-with-submodule .所以我做 git checkout ,但得到了错误:
    fatal: not a git repository: src/vendor/mysubmodule/../../../../../.git/modules/src/vendor/mysubmodule
    

    如何修复它,以便带有子模块的分支有它,而没有子模块的分支没有,并且我可以使用 git checkout 自由地来回切换?

    最佳答案

    我已经 1-2 天想知道有什么问题。
    这是我迄今为止找到的最近似(而且非常糟糕)的答案的链接:

    Checkout branch with different submodules is not working

    并快速回答:

    Supposing, for example, branch master has submodule A and branch alpha has submodule B.
    
    To properly checkout master you should, essentially
    git submodule deinit .
    git checkout master
    git submodule update --init --recursive
    
    To go back to alpha, again
    git submodule deinit .
    git checkout alpha
    git submodule update --init --recursive
    

    关于git - 如何从没有子模块的分支 check out 带有子模块的分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466231/

    相关文章:

    Git checkout 分支并修剪与先前 checkout 相关的所有内容(包括 git-lfs 保留)

    Git 子模块 URL 不包括用户名?

    git-submodules - JGit:从子模块中读取提交

    git - 如何使用存储在不同计算机之间的保管箱中的 git master 同步/更新文件?

    Python setup.py,GitLab 上的私有(private)存储库作为基于提交 ID 的 dependency_links

    git - bash git 预提交 Hook 运行 MatLab 函数不等待结果

    git - 如何正确管理子目录中被父目录忽略的 git repo 作为自己的项目?

    git - merge 时如何防止分离的HEAD?

    git - 如何删除 git MERGE_MSG?

    linux - 从裸 git 存储库中的钩子(Hook)导出文件