我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):

git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push

但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。


当前回答

对于那些使用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

我做了什么:

克隆存储库到一个文件夹 cd现有项目 这里打开一个git终端 git remote set-url origin <NEW_GIT_REPO> Git push -u origin——all Git push origin—tags

这工作移动我的本地回购(包括历史)到我的远程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上找到了这个

我使用下面的方法通过维护所有分支和提交历史来将我的GIT Stash迁移到GitLab。

将旧的存储库克隆到本地。

git clone --bare <STASH-URL>

在GitLab中创建一个空存储库。

git push --mirror <GitLab-URL>

我认为您正在寻找的命令是:

cd repo2
git checkout master
git remote add r1remote **url-of-repo1**
git fetch r1remote
git merge r1remote/master --allow-unrelated-histories
git remote rm r1remote

之后,repo2/master将包含来自repo2/master和repo1/master的所有内容,并且还将包含它们的历史。