【问题标题】:How to change git subrepo to track a differentt branch?如何更改 git subrepo 以跟踪不同的分支?
【发布时间】:2023-01-10 14:44:17
【问题描述】:

我在 ext/[subrep] 目录中有一个 subrepo,我想跟踪不同的分支。

我已按照 https://github.com/ingydotnet/git-subrepo/wiki/FAQ 上的切换子仓库分支的说明进行操作,但是,它似乎不起作用。

首先,由于 subrepo 中的代码及其父代码不是生产就绪代码,我希望这个 subrepo 位于一个独立的分支上。

为了更好地跟踪引用,我创建了一个新分支,然后将之前跟踪的分支中的所有现有工作合并到新分支中。

如果我明确地按照说明进行操作,即没有指定子存储库所在的确切目录,我将获得一个新目录,而不是简单地更改 .gitrepo 文件中的分支引用。

将我现有的工作与新分支合并后,如果我随后指定远程 URL、我要跟踪的分支和现有目录,克隆只会告诉我子仓库是最新的,而无需更改任何内容——甚至指定了 --force 标志。

我必须做的是

  1. git subrepo clean ext/[subrepodir]
  2. git rm -r -f ext/[subrepodir]
  3. 物理删除 ext/[subrepodir](在没有先删除目录的情况下在此处克隆 subrepo 会给出目录非空错误,即使使用 --force 标志也是如此。
  4. git 提交
  5. git subrepo clone [remoteURL] ext/[subrepodir] --force -b new_branch

    上面的结果是 subrepo 正确地跟踪了新的分支。然而,从常见问题解答看来,我不应该为了切换子仓库跟踪的分支而经历所有这些。

    这是一个错误吗?

【问题讨论】:

    标签: git git-track git-subrepo


    【解决方案1】:

    我以前从未使用过子模块,遇到一篇文章可能会解决你的问题,请阅读它,它写得很好。 关于切换子模块中的默认分支,运行以下命令:

    # "DbConnector" is the submodule name, and "stable" is the expected branch of the submodule
    git config -f .gitmodules submodule.DbConnector.branch stable
    

    参考文章:https://git-scm.com/book/en/v2/Git-Tools-Submodules

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 2014-10-07
      • 2019-03-08
      • 1970-01-01
      • 2016-08-09
      • 2018-12-11
      • 2011-02-24
      • 1970-01-01
      相关资源
      最近更新 更多