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


当前回答

备注:

git copy http://a.com/old.git http://a.com/new.git

仅适用于例如,一个github到github拷贝,即保留在相同的git系统。当从例如github复制到gerrit时,这是不工作的。

除此之外,它还很好用,因为它自动复制分支、标记和子模块。

其他回答

可以使用如下命令:

git remote set-url --push origin new_repo_url

例子来自http://gitref.org/remotes/

$ git remote -v
github  git@github.com:schacon/hw.git (fetch)
github  git@github.com:schacon/hw.git (push)
origin  git://github.com/github/git-reference.git (fetch)
origin  git://github.com/github/git-reference.git (push)
$ git remote set-url --push origin git://github.com/pjhyett/hw.git
$ git remote -v
github  git@github.com:schacon/hw.git (fetch)
github  git@github.com:schacon/hw.git (push)
origin  git://github.com/github/git-reference.git (fetch)
origin  git://github.com/pjhyett/hw.git (push)

我只是在一个简单的指导列表中转发别人说过的话。

Move the repository: Simply login to the new server, cd to the parent directory where you now want to hold the repository, and use rsync to copy from the old server: new.server> rsync -a -v -e ssh user@old.server.com:path/to/repository.git . Make clients point to the new repository: Now on each client using the repository, just remove the pointer to the old origin, and add one to the new one. client> git remote rm origin client> git remote add origin user@new.server.com:path/to/repository.git

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

git clone --mirror [oldUrl]

用所有分支克隆旧的回购

cd the_repo
git remote add remoteName newRepoUrl

设置一个新的遥控器

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

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

更新为使用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

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

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

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

效果好极了!