【问题标题】:How to migrate from one Git repo to another Git repo?如何从一个 Git 存储库迁移到另一个 Git 存储库?
【发布时间】:2020-10-25 20:26:39
【问题描述】:

我需要从一个 Git 存储库迁移到另一个 Git 存储库。目的地不为空。过去有人显然已经做了这项工作,但现在所有的分支都已经过时了。

情况是这样的:

源远程仓库:repo_source

分支机构:

  • branch_A
  • branch_B
  • branch_C
  • branch_D

目标远程仓库:repo_dest 分支:

  • branch_A
  • branch_B

想法是让缺失的分支(branch_C、branch_D)和已经存在的分支(branch_A、branch_B)需要用新数据进行更新。

作为示例,这里只有 4 个分支,但实际上更多。那么,有没有一种方法(脚本)可以让这种迁移变得简单?

【问题讨论】:

    标签: git version-control gitlab


    【解决方案1】:

    使用 git clone 命令克隆存储库 repo_source。

    git clone repo_source
    

    完成后,

    git remote add repo_dest repo_dest_url
    git push --force --all repo_dest 
    

    即使存在,这也应该替换所有目标分支。

    【讨论】:

    • 我建议先尝试不使用--force,如果它有效,那很好,如果它在强制之前不考虑问题。
    【解决方案2】:

    您可以将repo_dest 存储库添加为另一个远程,然后在本地拉取并合并更改并推送它们。

    从您的本地工作目录尝试以下操作;

    git remote add new_origin ORIGIN_URL           # add new remote
    git pull new_origin branch_A                   # pull, merge branch_A and fix conflicts (if any)
    git pull new_origin branch_B                   # pull, merge branch_B and fix conflicts (if any)
    git push new_origin branch_A                   # push each branch to the new remote
    git push new_origin branch_B
    git push new_origin branch_C
    git push new_origin branch_D
    

    【讨论】:

    • 是的,我正在做类似的事情,但我收到消息 Branch 'master' set up to track remote branch 'master' from 'repo_dest'。一切都是最新的。并没有真正发生它似乎忽略了 --all param
    • 那么不要使用--all。分别推送每个分支。
    • 你可以做的另一件事。签出master到新分支,删除本地master分支,推送所有分支,恢复master分支。
    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 2015-09-14
    • 2023-04-06
    • 2016-07-14
    • 1970-01-01
    • 2010-10-30
    • 2013-01-04
    相关资源
    最近更新 更多