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


当前回答

可以使用如下命令:

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)

其他回答

我按照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

对我来说很管用。

这在其他答案中也有部分体现。

git clone --mirror git@oldserver:oldproject.git
cd oldproject.git
git remote add new git@newserver:newproject.git
git push --mirror new

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

git clone --mirror [oldUrl]

用所有分支克隆旧的回购

cd the_repo
git remote add remoteName newRepoUrl

设置一个新的遥控器

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

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

这是这个答案的一个变体,目前gitlab建议将一个git存储库从一个服务器“迁移”到另一个服务器。

让我们假设您的旧项目名为existing_repo,存储在existing_repo文件夹中。 在新服务器上创建一个回购。我们假设这个新项目的url是git@newserver:newproject.git 打开命令行界面,输入如下信息: cd existing_repo Git远程重命名原点old-origin Git远程添加源git@newserver:newproject.git Git push -u origin——all Git push -u origin——tags

这种方法的好处是不需要删除与旧服务器相对应的分支。

要添加新的回购位置,

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