详解git仓库迁移的两种解决方案
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,Git仓库迁移而不丢失log的方法要求能保留原先的commit记录,应该如何迁移呢?同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢?注意:如果使用了代码审核工具Gerrit,那么
千家信息网最后更新 2026年11月03日详解git仓库迁移的两种解决方案
Git仓库迁移而不丢失log的方法
要求能保留原先的commit记录,应该如何迁移呢?
同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢?
注意:如果使用了代码审核工具Gerrit,那么在进行操作之前需要将Gerrit关掉,等成功恢复后再将Gerrit开户即可
1、使用git push --mirror
先了解一些git的基本参数介绍
git clone --bare
GIT-CLONE(1) Git Manual GIT-CLONE(1)NAME git-clone - Clone a repository into a new directorySYNOPSIS git clone [--template=] [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror] [-o ] [-b ] [-u ] [--reference ] [--depth ] [--recursive] [--] [ ] --bare Make a bare GIT repository. That is, instead of creating and placing the administrative files in /.git, make the 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. .mirror is set.
1、建立新仓库
1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub,或者是本地的私有仓库
git clone --bare git://192.168.10.XX/git_repo/project_name.git
2). 然后到新的 Git 服务器上创建一个新项目,比如 GitCafe,亦或是本地的私有仓库,如192.168.20.XX
su - gitcd /path/to/path/mkdir new_project_name.gitgit init --bare new_project_name.git
3). 以镜像推送的方式上传代码到 GitCafe 服务器上。
请确保已经添加了公钥到新的机器上
cd project_name.gitgit 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地址就行。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
仓库
地址
代码
服务器
服务
内容
方式
方法
版本
切换
私有
配置
成功
公钥
原本
参数
同时
名字
就是
工具
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技企业
易互联网科技有限公司
互联网科技股票
四川狮子座互联网科技
互联网 科技服务平台
重庆科技学院互联网
卫星互联网科技股票
江苏南京365互联网科技
昭通云南众福互联网科技有限公司
互联网校园科技培训
互联网科技公司实习生
深圳艾果互联网通讯科技
玉溪新华互联网科技好不好
济南有互联网科技公司吗
上海钢联属于互联网科技股吗
启辰互联网科技
厦门江牛科技互联网
兰石爱特工业互联网科技分公司
深圳互联网科技园地址
互联网科技对化妆品行业
互联网科技工作委员会
西安纸贵互联网科技有限公司
互联网科技活动banner
互联网教育科技公司vipkid
深圳艾果互联网通讯科技
朱啸虎曾投资哪些互联网科技企业
山东子淼互联网科技有限公司
本届互联网大会上的黑科技
互联网科技收购价值
银川新华互联网科技学校招聘