详解git仓库迁移的两种解决方案

 更新时间:2018年07月03日 09:00:52   作者:ZhangRuoxu  
这篇文章主要介绍了详解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 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 服务器上创建一个新项目,比如 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地址就行。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Kloxo面板无法登录出现500错误的解决方法

    Kloxo面板无法登录出现500错误的解决方法

    这篇文章主要介绍了Kloxo面板无法登录出现500错误的解决方法,需要的朋友可以参考下
    2015-10-10
  • 服务器(VPS)安装WebSite Panel面板教程(图文)

    服务器(VPS)安装WebSite Panel面板教程(图文)

    这篇文章主要为大家分享下WebsitePanel的安装方法,WebsitePanel简称WSP是微软旗下,开源免费的虚拟主机系统,需要win2008 r2环境
    2013-12-12
  • PHP 木马攻击的防御设置方法

    PHP 木马攻击的防御设置方法

    本文通过介绍一些技巧介绍了针对PHP木马攻击的防御之道,通过这些方面您能够更好的防范木马程式。
    2009-10-10
  • 浅析NFS服务器原理以及搭建配置部署步骤

    浅析NFS服务器原理以及搭建配置部署步骤

    本文对NFS服务器原理作了简要的分析,对NFS服务器的搭建配置步骤作了详细的图文描述,有需要的朋友可以借鉴参考下,希望可以对你有所帮助
    2021-08-08
  • CentOS下搭建SVN服务器的步骤详解

    CentOS下搭建SVN服务器的步骤详解

    这篇文章主要介绍了CentOS下搭建SVN服务器的步骤,较为详细的分析了CentOS平台上搭建SVN服务器的步骤与相关操作注意事项,需要的朋友可以参考下
    2016-10-10
  • Mac环境下搭建svn环境和使用方法

    Mac环境下搭建svn环境和使用方法

    本篇文章主要介绍了Mac环境下搭建svn环境的使用方法。由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,只需要简单配置,有兴趣的可以了解一下。
    2017-02-02
  • squid3缓存服务器编译安装和高命中率配置示例

    squid3缓存服务器编译安装和高命中率配置示例

    这篇文章主要介绍了squid3缓存服务器编译安装和高命中率配置示例,本文讲解了下载squid、编译安装squid、配置squid等内容,需要的朋友可以参考下
    2014-12-12
  • Centos服务器部署前后端项目的实战教程

    Centos服务器部署前后端项目的实战教程

    这篇文章主要介绍了Centos服务器部署前后端项目的实战教程,本文通过实例图文结合实例代码给大家介绍的非常详细,需要的朋友参考下吧
    2024-02-02
  • 在Mac下如何安装phpredis扩展

    在Mac下如何安装phpredis扩展

    这篇文章主要介绍了从windows转到Mac下,如何安装phpredis扩展,首先大家要先下载phpredis扩展,然后用命令进入文件夹,有需要的朋友可以来参考下。
    2015-07-07
  • 用nginx+FastDFS一步步搭建文件管理系统

    用nginx+FastDFS一步步搭建文件管理系统

    FastDFS 是一个开源的高性能分布式文件系统(DFS)。 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡。主要解决了海量数据存储问题,特别适合以中小文件(建议范围:4KB < file_size <500MB)为载体的在线服务
    2020-10-10

最新评论