【问题标题】:How to combine multiple git repos' branches as a single repo's branches?如何将多个 git repos 的分支合并为一个 repo 的分支?
【发布时间】:2020-03-24 18:02:14
【问题描述】:

我想组织我的 git 存储库,因为其中多个是高度相关的。现在我想将它们全部合并(而不是合并)到一个带有多个分支的单一仓库中,并删除旧的仓库。我该怎么办?

例如,我有带有分支 A.master、A.branch1、B.master、C.master、C.branch2 的 repo A、B 和 C。我想要的是创建一个新的仓库 D,其分支是 D.master(新事物)、A.master(必须更改名称)、A.branch1、B.master(必须更改名称)、C.master(有更改名称),C.branch2 以及原始存储库中的所有提交历史记录。然后删除A、B、C,这样子模块就不能使用了。

【问题讨论】:

  • 是的,这就是你必须做的:在有冲突的地方想出新的名字。您的实际问题是什么?
  • 我的问题是如何做所有这些组合。我想将不同的存储库合并为一个并保留所有提交历史记录。该怎么做?

标签: git gitlab repository


【解决方案1】:

希望这会有所帮助。

您创建了一个名为 D 的新存储库。

  • 要在 repo A 中运行的命令
 1. git remote add repoD https://github.com/****/repod.git
 2. git checkout master (go to master branch of A)
 3. git co -b master_of_a
 4. git push -u repoD master_of_a

repeat the below steps for other branches in the repo A. Below example give for branch1 in the repo A

 1. git checkout branch1 (go to branch1 of A)
 3. git co -b branch1_of_a
 4. git push -u repoD branch1_of_a

  • 对所有 repos 和所有分支重复上述两个步骤。

是的。也存储提交历史记录

【讨论】:

    【解决方案2】:

    假设你有 repo A、B 和 C,并且你创建了一个新的 repo D。
    假设您将被签出到您将要合并的正确分支
    例如。

    $> cd A
    $> git checkout master
    

    然后将旧仓库分支的远程添加到新仓库

    $> cd D
    $> git remote add A "path to A"
    $> git remote update
    

    ... 此时我只是复制粘贴这个答案Merge git repo into branch of another repo

    【讨论】:

    • 此解决方案是否保留所有提交历史记录?
    • 做了一些快速挖掘,虽然我个人无法确认这一点,因为我没有测试过,请查看描述类似 stackoverflow.com/questions/17371150/… 的答案
    猜你喜欢
    • 2014-02-16
    • 1970-01-01
    • 2012-04-30
    • 2016-03-23
    • 2010-12-15
    • 2012-02-24
    • 2019-03-11
    • 2012-06-21
    • 1970-01-01
    相关资源
    最近更新 更多