将Git存储库内容移至另一个保存历史logging的存储库

我试图只使用以下命令将一个存储库(比如repo1)的内容移动到另一个现有存储库(比如说repo2);

  1. git clone repo1
  2. git clone repo2
  3. cd repo1
  4. git remote rm origin
  5. git remote add repo1
  6. 混帐推

但它不工作。 我审查了其他类似的post,但我只发现移动文件夹不是内容。

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

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/masterrepo1/master ,同时也会包含两者的历史logging。

这里完美描述https://www.smashingmagazine.com/2014/05/moving-git-repository-new-server/

首先,我们必须从现有的仓库获取所有的远程分支和标签到我们的本地索引:

 git fetch origin 

我们可以检查任何缺失的分支,我们需要创build一个本地副本:

 git branch -a 

让我们使用我们新存储库的SSH克隆的URL在我们现有的本地存储库中创build一个新的远程:

 git remote add new-origin git@github.com:manakor/manascope.git 

现在我们准备将所有本地分支和标签推送到名为new-origin的新远程:

 git push --all new-origin git push --tags new-origin 

让我们将新来的默认远程:

 git remote rm origin 

将新来源重命名为原点,以使其成为默认的远程:

 git remote rename new-origin origin 

看起来你很接近 假设你的提交不只是一个错字,第3步应该是cd repo2而不是repo1。 而第六步应该是git pull不推。 返工列表:

 1. git clone repo1 2. git clone repo2 3. cd repo2 4. git remote rm origin 5. git remote add repo1 6. git pull 7. git remote rm repo1 8. git remote add newremote 

如果你想保留现有的分支机构并提交历史logging,这里有一个方法适用于我。

 git clone --mirror https://github.com/account/repo.git cloned-repo cd cloned-repo git push --mirror {URL of new (empty) repo} 

现在,假设您希望在一段时间内保持源和目标库的同步。 例如,当前的远程仓库中还有一些活动要交给新的/replace的仓库。

 git clone -o old https://github.com/account/repo.git my-repo cd my-repo git remote add new {URL of new repo} 

要取消最新更新(假设您没有本地更改):

 git checkout {branch(es) of interest} git pull old git push --all new 

注:我还没有使用子模块,所以我不知道如果你有它们可能需要额外的步骤。

这里有很多复杂的答案。 但是,如果您不关心分支保存,则只需重置远程原点,设置上游,然后按下即可。

这工作保存所有提交历史对我来说。

 cd <location of local repo.> git remote set-url origin <url> git push -u origin master 

这工作将我的本地回购(包括历史)移动到我的远程github.com回购。 在GitHub.com上创build新的空回购之后,我在下面的第三步中使用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