我有个服务器要关闭。我剩下要迁移的唯一东西是我的存储库。这个服务器被列为我的一个项目的原始(主)服务器。移动存储库以保存历史的正确方法是什么?


当前回答

更新为使用git push——mirror origin而不是评论中建议的git push -f origin。


这个方法对我来说完美无缺。

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 --mirror origin

我不得不提的是,这将创建当前回购的镜像,然后将其推到新位置。因此,对于大型回购或慢速连接,这可能需要一些时间。

其他回答

如果你想从一个源移动到另一个源,并在本地机器上保留当前源的备份,可以使用以下步骤:

首先在本地找到你想要移动的(git)文件夹 在线创建新的存储库 此步骤创建一个存储库,我们可以将代码推入其中

现在在文件夹里做

git remote get-url origin

上面的命令给出了当前的远程原点url,这对于在最后一步中将原点设置回很有用

git remote set-url origin git@github.newlocation:folder/newrepo.git

上面的命令将远程原点设置为新位置

git push --set-upstream origin develop

上面的命令将当前活动的本地分支推到使用branchname develop的远程分支。当然,它会保存所有历史,因为git也会推送所有历史。

git remote set-url origin <original old origin>

上面的命令将远程原点设置回您的当前原点:您需要这样做是因为您在现有文件夹中,并且您可能不希望将当前本地文件夹名称与您将要创建的用于克隆您刚刚推入的repo的新文件夹混淆。

希望这能有所帮助,

复制一遍。就是这么简单。:)

在客户端,只需在客户端的本地repo中编辑.git/config,以便根据需要将您的遥控器指向新的URL。

如果你想迁移所有的分支和标签,你应该使用以下命令:

git clone --mirror [oldUrl]

用所有分支克隆旧的回购

cd the_repo
git remote add remoteName newRepoUrl

设置一个新的遥控器

git push -f --tags remoteName refs/heads/*:refs/heads/*

将所有的refs放在refs/heads下(这可能是你想要的)

我按照BitBucket上的说明移动了一个回购,所有分支都在那里。下面是#字符后面的步骤和解释:

cd path/to/local/repo
git remote remove origin # to get rid of the old setting, this was not in the BitBucket instructions
git remote add origin ssh://git@bitbucket.org/<username>/<newrepo> # modify URL as needed
git push -u origin --all # pushes _ALL_ branches in one go
git push -u origin --tags # pushes _ALL_ tags in one go

对我来说很管用。

看看GitHub上的这个食谱: https://help.github.com/articles/importing-an-external-git-repository

在发现git push -mirror之前,我尝试了许多方法。

效果好极了!