简体   繁体   English

如何从一个 Git 存储库迁移到另一个 Git 存储库?

[英]How to migrate from one Git repo to another Git repo?

I need to do a migration from one Git repo to another Git repo.我需要从一个 Git 存储库迁移到另一个 Git 存储库。 The destination is not empty.目的地不为空。 Someone in the past already did this work apparently, but now all the branches are outdated.过去有人显然已经做了这项工作,但现在所有的分支都已经过时了。

This is the situation:这是这种情况:

Source remote repository: repo_source源远程存储库: repo_source

branches:分支机构:

  • branch_A分支_A
  • branch_B分支_B
  • branch_C分支_C
  • branch_D分支_D

Destination remote repository: repo_dest branches:目标远程存储库: repo_dest分支:

  • branch_A分支_A
  • branch_B分支_B

The idea is to have the missing branches (branch_C, branch_D) and the already existing branches (branch_A, branch_B) need to be updated with the new data.这个想法是让缺失的分支(branch_C,branch_D)和已经存在的分支(branch_A,branch_B)需要用新数据进行更新。

As example here there are just 4 branches, but in realty is way more.例如这里只有 4 个分支,但实际上更多。 So, is there a way (a script) for make this migration simple?那么,有没有一种方法(脚本)可以使这种迁移变得简单?

Clone repository repo_source using the git clone command.使用 git 克隆命令克隆存储库 repo_source。

git clone repo_source

Once done,一旦完成,

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

This should replace all the destination branches too even if it exists.即使存在,这也应该替换所有目标分支。

You can add the repo_dest repository as another remote and then pull and merge the changes locally and push them.您可以将repo_dest存储库添加为另一个远程存储库,然后在本地提取和合并更改并推送它们。

Try the below from your local working directory;从您的本地工作目录尝试以下操作;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM