詳解git倉庫遷移的兩種解決方案
Git倉庫遷移而不丟失log的方法
要求能保留原先的commit記錄,應該如何遷移呢?
同時,本地已經clone了原倉庫,要配置成新的倉庫地址,該如何修改呢?
注意:如果使用了代碼審核工具Gerrit,那么在進行操作之前需要將Gerrit關掉,等成功恢復后再將Gerrit開戶即可
1、使用git push --mirror
先了解一些git的基本參數(shù)介紹
git clone --bare
GIT-CLONE(1) Git Manual GIT-CLONE(1) NAME git-clone - Clone a repository into a new directory SYNOPSIS git clone [--template=<template_directory>] [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror] [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>] [--depth <depth>] [--recursive] [--] <repository> [<directory>] --bare Make a bare GIT repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created. git push --mirror --mirror Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.
1、建立新倉庫
1). 從原地址克隆一份裸版本庫,比如原本托管于 GitHub,或者是本地的私有倉庫
git clone --bare git://192.168.10.XX/git_repo/project_name.git
2). 然后到新的 Git 服務器上創(chuàng)建一個新項目,比如 GitCafe,亦或是本地的私有倉庫,如192.168.20.XX
su - git cd /path/to/path/ mkdir new_project_name.git git init --bare new_project_name.git
3). 以鏡像推送的方式上傳代碼到 GitCafe 服務器上。
請確保已經添加了公鑰到新的機器上
cd project_name.git git push --mirror git@192.168.20.XX/path/to/path/new_project_name.git
4). 刪除本地代碼
cd .. rm -rf project_name.git
5). 到新服務器上找到 Clone 地址,直接Clone到本地就可以了。
git clone git@192.168.20.XX/path/to/path/new_project_name.git
這種方式可以保留原版本庫中的所有內容。
2、切換remote_url
先查看remote的名字
git branch -r
假設你的remote是origin,用git remote set_url 更換地址
git remote set-url origin remote_git_address
remote_git_address更換成你的新的倉庫地址。
第二種切換remote_url的方法更直接,直接更改.git/conf配置文件里的ip地址就行。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
用phpMyadmin創(chuàng)建Mysql數(shù)據(jù)庫及獨立數(shù)據(jù)庫帳號的圖文教程
在一個服務器上一般來講都不止一個站點,更不止一個MySQL(和PHP搭配之最佳組合)數(shù)據(jù)庫。2010-03-03多核心服務器和高主頻服務器怎么選?cpu主頻高和核心多哪個更好?
這篇文章主要介紹了多核心服務器和高主頻服務器怎么選?cpu主頻高和核心多哪個更好?,需要的朋友可以參考下2023-07-07ubuntu20.04安裝unity-tweak-tools啟動時遇到錯誤的解決
在Ubuntu系統(tǒng)中,安裝Unity Tweak Tool時可能會遇到schemacom.canonical.Unity.ApplicationsLens未安裝的錯誤,解決這個問題的辦法是安裝缺失的依賴包,執(zhí)行命令`sudo apt-get install unity-lens-applications` 和 `sudo apt-get install unity-lens-files`2024-09-09windows服務器之win2003,win2008R2,win2012,win2016,win2019系統(tǒng)版本區(qū)別
windows服務器版有window2003,windows server2008,windows server2012 R2,windows server2016,windows 2019他們有什么不同,如何選擇適合自己的服務器系統(tǒng),需要的朋友可以參考下2020-02-02VScode連接遠程服務器踩坑實戰(zhàn)記錄(新版離線vscode-server安裝)
本文主要介紹了如何使用VScode連接遠程服務器,并對離線安裝vscode-server進行了詳細的操作步驟說明,其中包括VScode擴展的安裝與配置,vscode-server的離線下載,文件的解壓縮和移動,以及VScode的一些更新設置,能夠幫助讀者更好地理解和掌握VScode連接遠程服務器的方法2024-10-10采用軟件負載均衡器實現(xiàn)web服務器集群(iis+nginx)
我用nginx實現(xiàn)網站負載均衡測試的例子,windows下IIS做負載實測2016-04-04