如何将GIT存储库从一台服务器迁移到新服务器

我有一台要关闭的服务器。我剩下的唯一要迁移的是我的存储库。该服务器被列为我的一个项目的来源(主服务器)。移动存储库以保留历史记录的正确方法是什么?



白衣非少年
浏览 857回答 3
3回答

杨__羊羊

要添加新的回购位置,git remote add new_repo_name new_repo_url然后将内容推送到新位置git push new_repo_name master最后删除旧的git remote rm origin之后,您可以执行bdonlan所说的操作,然后编辑.git / config文件以将new_repo_name更改为origin。如果您不删除原始资源(原始远程存储库),则只需使用以下命令将更改推送到新存储库即可git push new_repo_name master

九州编程

如果要迁移所有分支和标记,则应使用以下命令:git clone --mirror [oldUrl]用所有分支克隆旧仓库cd the_repogit remote add remoteName newRepoUrl设置一个新的遥控器git push -f --tags remoteName refs/heads/*:refs/heads/*将所有裁判推到裁判/门下(这可能是您想要的)

慕码人8056858

这完美地为我工作。git clone --mirror <URL to my OLD repo location>cd <New directory where your OLD repo was cloned>git remote set-url origin <URL to my NEW repo location>git push -f origin我必须提到,这会创建您当前回购的镜像,然后将其推送到新位置。因此,对于大型存储库或缓慢的连接,这可能需要一些时间。
打开App,查看更多内容
随时随地看视频慕课网APP