【问题标题】:How to delete a remote branch of a submodule (Git)如何删除子模块的远程分支(Git)
【发布时间】:2019-02-26 01:00:07
【问题描述】:

在名为 Repo 的 Git 存储库中有 4 个子模块:

git config --file .gitmodules --name-only --get-regexp path

submodule.A/lib1
submodule.A/lib2 
submodule.lib3 
submodule.lib4

假设lib1 子模块上有一个名为Prototype远程分支,它不再需要:

git submodule foreach 'git branch -a | grep -i prototype || true'

Entering 'path-to-lib1/lib1'
  remotes/origin/FeatureA
  remotes/origin/Prototype
Entering 'path-to-lib2/lib2'
  remotes/origin/FeatureB
Entering 'path-to-lib3/lib3'
Entering 'path-to-lib4/lib4'
  remotes/origin/FeatureC

如何从lib1 子模块删除这个Prototype 远程分支?

我尝试了以下方法:

git push origin --delete Prototype

git push origin --delete origin/Prototype

git push origin --delete remotes/origin/Prototype

以上所有 3 个命令都给出了错误:

error: unable to delete 'Prototype': remote ref does not exist 
error: failed to push some refs to 'repo-path'

我正在尝试理解子模块的主题,但我偶然发现了这个问题,通过一些在线搜索我无法找到答案。

任何带有解释的命令/建议将不胜感激。

【问题讨论】:

    标签: git git-branch git-submodules


    【解决方案1】:

    将目录更改为子模块,然后git push --delete origin Prototype

    【讨论】:

      【解决方案2】:

      您将子模块中的分支删除为独立存储库,而不是超级项目:

      cd path-to-lib1/lib1
      git branch -d Prototype
      git push origin --delete Prototype
      cd ../..  # back to superproject
      

      【讨论】:

      • 谢谢您的回答;我对你的答案有点困惑(git branch -d Prototype` 然后git push origin --delete Prototype 与@Horbas 的git push --delete origin Prototype 不同。你能解释一下吗?
      • git branch -d 删除本地子模块存储库中的分支; git push --delete 远程删除。
      猜你喜欢
      • 1970-01-01
      • 2015-07-03
      • 2016-01-09
      • 2020-04-12
      • 2013-07-06
      • 2013-11-27
      • 2012-02-24
      • 2013-01-07
      相关资源
      最近更新 更多