【问题标题】:Git Subtree Merge - Merge all branches in subtree repo into parent repo at same timeGit Subtree Merge - 将子树仓库中的所有分支同时合并到父仓库中
【发布时间】:2017-04-14 04:39:59
【问题描述】:

是否可以使用 Git 子树合并,通过一个 Git 命令同时将 Repo B 的所有分支合并到 Repo A 中?回购 B 有近 15 个不同的分支,我试图通过一次对回购及其所有分支进行子合并来节省时间。我还没有找到任何方法可以在网上做到这一点..这不可能吗?

如果不可能,是否有人知道将每个分支单独合并到父 Repo A 的最有效方法。Repo B 看起来像这样:

 Repo B/masterbranch
 Repo B/developbranch
 Repo B/featurebranch

我需要 Repo A(父级)看起来像这样:

 Repo A
  component -> folder of some sort that holds the different branches
     masterbranch
     developbranch
     featurebranch

我知道我可以通过 subTree 合并保留历史记录,所以我想我需要在这方面做点什么。但似乎只能一次执行一个分支,导致我的 .bowerrc 中的文件冲突

我最初一次做一个文件的尝试是从以下几点开始的:

How do you merge two Git repositories?

【问题讨论】:

  • 您是说,对于最终产品,您希望“Repo A”拥有一个“组件”目录,其中“Repo B”的每个分支都有一个单独的子目录?
  • 只有一个“组件”目录,在目录中我可以选择一个特定的分支并查看它的历史记录。

标签: git github version-control merge git-subtree


【解决方案1】:

是的,你可以通过两种方式来实现——子模块和添加远程(不带子树):

按子模块:

  1. 在 repo A 中,添加 repo B 作为子模块,使用git submodule add <URL for Repo B> component
  2. 在组件(cd component)的子文件夹中,您将找到 Repo B(git branch -a)的所有分支。现在 Repo B 中的分支作为 Repo A 的一部分存在。您可以切换到 Repo B 的不同分支
  3. 如果要在 Repo A 中提交 Repo B 的更改,则需要回到 Repo A 目录(cd ..),然后使用 git commit 和 git push 到 Repo A。如果要更改 Repo B 在 Repo B 本身提交,你可以在组件子文件夹(cd component),然后使用git commit 和git push。

通过添加遥控器:

  1. 在本地 Repo A 中添加 Repo B 远程,使用 git remote add origin1 <URL for Repo B>
  2. 拉回购git pull origin1
  3. 但这可能与您的要求有点不同,Repo A 和 Repo B 的所有分支都在同一个目录下,显示为 (git branch -a):

remotes/origin/<all Repo A branches> remotes/origin1/<all Repo B branches>

注意:你可以切换到任何一个分支。如果 Repo A 和 Repo B 都有 master 分支,则需要添加远程名称,例如 git checkout origin/master 或 git checkout origin1/master

【讨论】:

  • 我按照上述步骤使用了 submodules 方法......它确实将 Repo B 添加为子模块,但它创建的目录是“component @ 65c69279bb2”,它还创建了一个“.gitmodules”文件夹。我可以继续将该文件夹重命名为“组件”吗?这有什么影响吗?另外,我可以删除 .gitmodules 文件夹还是需要那个文件夹?
  • 在上面的评论中,我将 repo B 的更改提交到 Repo A。这就是我需要的,我只是不希望组件文件夹像上面那样命名..如果 gitmodule文件必须在那里我可以忍受..谢谢
  • 看来我必须使用远程选项。我看到 Repo A/component/ 中的所有分支都使用此选项...是否推送与上面链接中的步骤相同(即 read-tree --prefix=...)跨度>
  • 是的,Repo B(不是 Repo A)的所有分支都坐在Repo A/component
  • 您确实在遥控器上找到了名称component @ 65c69279bb2。但实际上目录的名称是component,它在远程显示component @ 65c69279bb2只是为了清楚地表明子模块是在提交65c69279bb2之后添加的。您可以通过再次克隆来验证,使用git clone --recursive &lt;URL for Repo A&gt;。所以你不需要重命名它。 .gitmodules 的文件无法删除,因为它定义了 Repo A 和 Repo B 之间的关系,所以保留它。希望这可以帮助你:)
猜你喜欢
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多