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


当前回答

如果你想把一个#git仓库从一个服务器迁移到一个新的服务器,你可以这样做:

git clone OLD_REPOSITORY_PATH
cd OLD_REPOSITORY_DIR
git remote add NEW_REPOSITORY_ALIAS  NEW_REPOSITORY_PATH
#check out all remote branches 
for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; done
git push --mirror NEW_REPOSITORY_PATH
git push NEW_REPOSITORY_ALIAS --tags

旧存储库中的所有远程分支和标记将被复制到新的存储库中。

单独运行该命令:

git push NEW_REPOSITORY_ALIAS

只复制一个主分支(只跟踪分支)到新的存储库。

其他回答

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

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-copy复制所有历史记录的回购。

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

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

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

可以使用如下命令:

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)

要添加新的回购位置,

git remote add new_repo_name new_repo_url

然后将内容推到新位置

git push new_repo_name master

最后去掉旧的

git remote rm origin

之后,你可以做什么bdonlan说,并编辑。Git /config文件修改new_repo_name为origin。如果您不删除原始(原始远程存储库),您可以简单地将更改推到新的repo with

git push new_repo_name master