我有一台要关闭的服务器。我剩下的唯一要迁移的是我的存储库。该服务器被列为我的一个项目的来源(主服务器)。移动存储库以保留历史记录的正确方法是什么?
我有一台要关闭的服务器。我剩下的唯一要迁移的是我的存储库。该服务器被列为我的一个项目的来源(主服务器)。移动存储库以保留历史记录的正确方法是什么?
Answers:
要添加新的回购位置,
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。如果您不删除原始资源(原始远程存储库),则只需使用以下命令将更改推送到新存储库即可
git push new_repo_name master
git push -u new_repo_name --all。
git remote rename new_repo_name origin
如果要迁移所有分支和标记,则应使用以下命令:
git clone --mirror [oldUrl]
用所有分支克隆旧仓库
cd the_repo
git remote add remoteName newRepoUrl
设置一个新的遥控器
git push -f --tags remoteName refs/heads/*:refs/heads/*
将所有裁判推到裁判/门下(这可能是您想要的)
refs/heads/refs/heads,git push -f --tags remoteName refs/heads/*:refs/heads/*所以我换成了git push remoteName --mirror
push也支持--mirror。git clone --mirror; cd repo; git push --mirror new_remote应该可以解决问题
这完美地为我工作。
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 -f origin
我必须提到,这会创建您当前回购的镜像,然后将其推送到新位置。因此,对于大型存储库或缓慢的连接,这可能需要一些时间。
git push --mirror origin超过-f。
复制过来。真的就是这么简单。:)
在客户端,只需在客户端的本地存储库中编辑.git / config即可根据需要将您的遥控器指向新的URL。
我只是按照简单的说明列表重新发布其他人说的话。
移动存储库:只需登录到新服务器,cd现在要保存存储库的父目录,然后用于rsync从旧服务器复制:
new.server> rsync -a -v -e ssh user@old.server.com:path/to/repository.git .
让客户端指向新的存储库:现在,在使用该存储库的每个客户端上,只需删除指向旧源的指针,然后将指针添加到新的指针即可。
client> git remote rm origin
client> git remote add origin user@new.server.com:path/to/repository.git
git remote set-url origin user@new.server.com:path/to/repository.git
在GitHub上查看此食谱:https: //help.github.com/articles/importing-an-external-git-repository
在发现之前,我尝试了多种方法 git push --mirror。
像魅力一样工作!
git clone --mirror ...,git remote add ...,git push --mirror ...
我按照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
对我来说很好。
这是此答案的一种变体,目前由gitlab建议将git存储库从一台服务器“迁移”到另一台服务器。
让我们假设您的旧项目名为existing_repo,存储在一个existing_repo文件夹中。
在新服务器上创建一个仓库。我们将假定该新项目的网址为git@newserver:newproject.git
打开命令行界面,然后输入以下内容:
cd existing_repo
git remote rename origin old-origin
git remote add origin git@newserver:newproject.git
git push -u origin --all
git push -u origin --tags
这种方法的好处是您不会删除与旧服务器相对应的分支。
您可以使用以下命令:
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 set-url origin git://new.url.here
这样,您可以origin为新存储库保留名称-然后将旧存储库推送到新存储库,如其他答案中所述。假设您一个人工作,并且有一个本地仓库,您想在其中镜像所有残骸,那么(在本地仓库内)您也可以
git push origin --mirror # origin points to your new repo
但是请参阅“ git push --mirror”是否足以备份我的存储库?(--mirror总计一次不使用)。
如果要从一个原点移动到另一个原点,并且还要在本地计算机上保留当前原点的备份,则可以使用以下步骤:
现在在文件夹中
git remote get-url origin
上面的命令提供了当前的远程源URL,在最后一步中将源设置回
git remote set-url origin git@github.newlocation:folder/newrepo.git
上面的命令将远程原点设置为新位置
git push --set-upstream origin develop
上面的命令将当前活动的本地分支推送到具有branchname开发的远程。当然,它会保留所有历史记录,因为使用git还会推送所有历史记录。
git remote set-url origin <original old origin>
上面的命令将远程原点设置回当前原点:您需要这样做,因为您位于现有文件夹中,并且可能不希望将当前的本地文件夹名称与要创建的用于克隆存储库的新文件夹混合使用你只是推到。
希望这可以帮助,
如果要将#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
只会将主分支(仅跟踪分支)复制到新存储库。