詳解git倉(cāng)庫(kù)遷移的兩種解決方案
Git倉(cāng)庫(kù)遷移而不丟失log的方法
要求能保留原先的commit記錄,應(yīng)該如何遷移呢?
同時(shí),本地已經(jīng)clone了原倉(cāng)庫(kù),要配置成新的倉(cāng)庫(kù)地址,該如何修改呢?
注意:如果使用了代碼審核工具Gerrit,那么在進(jìn)行操作之前需要將Gerrit關(guān)掉,等成功恢復(fù)后再將Gerrit開(kāi)戶即可
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、建立新倉(cāng)庫(kù)
1). 從原地址克隆一份裸版本庫(kù),比如原本托管于 GitHub,或者是本地的私有倉(cāng)庫(kù)
git clone --bare git://192.168.10.XX/git_repo/project_name.git
2). 然后到新的 Git 服務(wù)器上創(chuàng)建一個(gè)新項(xiàng)目,比如 GitCafe,亦或是本地的私有倉(cāng)庫(kù),如192.168.20.XX
su - git cd /path/to/path/ mkdir new_project_name.git git init --bare new_project_name.git
3). 以鏡像推送的方式上傳代碼到 GitCafe 服務(wù)器上。
請(qǐng)確保已經(jīng)添加了公鑰到新的機(jī)器上
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). 到新服務(wù)器上找到 Clone 地址,直接Clone到本地就可以了。
git clone git@192.168.20.XX/path/to/path/new_project_name.git
這種方式可以保留原版本庫(kù)中的所有內(nèi)容。
2、切換remote_url
先查看remote的名字
git branch -r
假設(shè)你的remote是origin,用git remote set_url 更換地址
git remote set-url origin remote_git_address
remote_git_address更換成你的新的倉(cāng)庫(kù)地址。
第二種切換remote_url的方法更直接,直接更改.git/conf配置文件里的ip地址就行。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
git沖突解決_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了git沖突解決,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
ubuntu系統(tǒng)筆記本電池壞掉性能下降(卡頓解決)
這篇文章主要為大家介紹了ubuntu系統(tǒng)筆記本電池壞掉性能下降(卡頓解決)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
服務(wù)發(fā)現(xiàn)與負(fù)載均衡機(jī)制Service實(shí)例創(chuàng)建
這篇文章主要為大家介紹了服務(wù)發(fā)現(xiàn)與負(fù)載均衡機(jī)制Service實(shí)例創(chuàng)建有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03
服務(wù)器安全問(wèn)題匯總 讓你的服務(wù)器更安全
下面是腳本之家從網(wǎng)站上看到的一篇介紹如何讓你的服務(wù)器更安全,需要注意的一些細(xì)節(jié),整理的比較不錯(cuò),維護(hù)服務(wù)器安全的朋友可以參考下。2010-07-07
Centos中VNC遠(yuǎn)程桌面程序的安裝與使用教程
這篇文章主要介紹了Centos中VNC遠(yuǎn)程桌面程序的安裝與使用的方法,較為詳細(xì)的分析了CentOS的VNC遠(yuǎn)程桌面程序安裝、配置、連接、啟動(dòng)等命令與相關(guān)操作技巧,需要的朋友可以參考下2016-07-07
SVN使用教程_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了SVN使用教程和注意事項(xiàng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
使用GIT進(jìn)行源碼管理——GUI客戶端小結(jié)
很多人對(duì)GIT GUI客戶端是非常不屑一顧的,但我非常喜歡GUI的方便快捷,也不用記憶冗雜的命令,本文簡(jiǎn)單的介紹了幾種免費(fèi)的Windows下的GIT客戶端,方便大家使用2014-09-09
Rsync實(shí)現(xiàn)文件定時(shí)同步技巧
這篇文章主要介紹了Rsync實(shí)現(xiàn)文件定時(shí)同步技巧的相關(guān)資料,需要的朋友可以參考下2015-09-09

