我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):
git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push
但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。
我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):
git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push
但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。
当前回答
这工作移动我的本地回购(包括历史)到我的远程github.com回购。在GitHub.com上创建新的空回购后,我使用下面第三步中的URL,它工作得很好。
git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror
我在https://gist.github.com/niksumeiko/8972566上找到了这个
其他回答
对于那些使用GitHub的人,你可以通过web UI导入另一个存储库(包括历史):
https://github.com/new/import
看起来你很接近了。假设不仅仅是提交一个错字,应该cd repo2代替repo1步骤3。第六步应该是拉而不是推。修改了列表:
Git克隆repo1 Git克隆repo2 cd repo2 Git远程rm来源 Git远程添加repo1 git拉 Git远程rm repo1 Git远程添加newremote
镜像存储库
根据@Dan-Cohn的回答,镜像推送是你的朋友。这是我的迁移回购:
1.打开Git Bash。
2.创建存储库的裸克隆。
$ git clone --bare https://github.com/exampleuser/old-repository.git
3.镜像推送到新的存储库。
$ cd old-repository.git
$ git push --mirror https://github.com/exampleuser/new-repository.git
4.删除在步骤1中创建的临时本地存储库。
$ cd ..
$ rm -rf old-repository.git
参考文献和出处:https://help.github.com/en/articles/duplicating-a-repository
我在这里看到了很多解决方案。一个是一个快速的一行,在过去为我工作是使用-mirror选项。先进入你想要复制的repo。然后假设你有一个新的回购已经设置,使用克隆链接,这就是它。它会复制所有历史到你的新回购。
光盘回购
Git——mirror linktonewrepo.git
我做了什么:
克隆存储库到一个文件夹 cd现有项目 这里打开一个git终端 git remote set-url origin <NEW_GIT_REPO> Git push -u origin——all Git push origin—tags