[英]How can I migrate the pull requests from one Git Server to another Git Server for a repository?
[英]How to migrate GIT repository from one server to a new one
我有一個服務器要關閉。 我唯一要遷移的是我的存儲庫。 該服務器被列為我的一個項目的源(主)。 移動存儲庫以保留歷史記錄的正確方法是什么。
要添加新的回購位置,
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 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
我不得不提一下,這會創建您當前存儲庫的鏡像,然后將其推送到新位置。 因此,對於大型存儲庫或慢速連接,這可能需要一些時間。
復制過來。 真的就是這么簡單。 :)
在客戶端,只需在客戶端的本地存儲庫中編輯 .git/config 以根據需要將您的遙控器指向新的 URL。
這是在其他一些答案中部分完成的。
git clone --mirror git@oldserver:oldproject.git
cd oldproject.git
git remote add new git@newserver:newproject.git
git push --mirror new
我只是在簡單易懂的說明列表中重新發布其他人所說的內容。
移動存儲庫:只需登錄到新服務器, 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
看看 GitHub 上的這個秘籍: https : //help.github.com/articles/importing-an-external-git-repository
在發現git push --mirror
之前,我嘗試了多種方法。
像魅力一樣工作!
我按照 BitBucket 上的說明移動了一個 repo 及其所有分支。 下面是#
字符后面的步驟和解釋:
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
文件夾中。
在您的新服務器上創建一個 repo。 我們假設新項目的 url 是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 origin git://new.url.here
通過這種方式,您可以保留新存儲庫的名稱origin
- 然后將舊存儲庫推送到新存儲庫,如其他答案中所述。 假設你一個人工作,並且你有一個本地倉庫,你想用你所有的東西來鏡像,你也可以(從你的本地倉庫內部)
git push origin --mirror # origin points to your new repo
但請參閱“git push --mirror”是否足以備份我的存儲庫? (總之不要使用--mirror
而是一次)。
您可以使用以下命令:
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 clone --bare <old-repo-url>
cd <old-repo-directory>
git push --mirror <new-repo-url>
您可以使用git-copy復制具有所有歷史記錄的 repo。
git copy http://a.com/old.git http://a.com/new.git
如果您想從一個源移動到另一個源並在本地計算機上保留當前源的備份,您可以使用以下步驟:
現在在文件夾中做
git remote get-url origin
上面的命令給出了當前遠程源 url,有助於在最后一步中將源設置回
git remote set-url origin git@github.newlocation:folder/newrepo.git
上面的命令將遠程原點設置為新位置
git push --set-upstream origin develop
上面的命令將當前活動的本地分支推送到分支名稱為 develop 的遠程。 當然,它會保留所有歷史記錄,因為 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
只會將主分支(僅跟蹤分支)復制到新存儲庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.