把在 A 托管平台的仓库完全的迁移到 B 托管平台,保留 commit 历史记录。
迁移前后,保留 commit 历史记录,即在迁移后的新仓库中能查询历史提交信息,同时也能保留小绿点。
在 GitHub 中新建一个同名项目(不同名也可以),不要添加 README.md,以及任何 License 和 .gitignore 文件,只需要新建一个空的仓库。
git clone https://git.coding.net/wenyuan/blog.git --bare
使用新仓库页面提供的仓库地址(web URL),推送所有的分支和对象
git push https://github.com/wenyuan/blog.git --all
git push https://github.com/wenyuan/blog.git --tags
这样,整个仓库就全部迁移到 GitHub 了,如果这些commit中的邮箱在GitHub配置中,可以看到小绿点也一起迁移过来了。
这种简单的操作我不是很喜欢用可视化工具,不过这里也介绍下怎么用「小乌龟」来完成仓库的迁移。
进入项目文件夹,鼠标右键 -> Git Sync…
点击 Manage。
填写 GitHub 远程仓库的信息,并 Add New/Save,应用,确认。
Remote URL 选则刚刚添加的 gitHub,然后 Push。
最后再提交 Tags.
四、git命令区别
上面在推送代码至 GitHub(新仓库)时,我们用到了下面这个命令:
git push https://github.com/wenyuan/blog.git --all
其实还有另外一个命令:
git push https://github.com/wenyuan/blog.git --mirror
关于这两个命令的区别,可以参见Git push –all vs –mirror。